Skip to main content
  1. Posts/

(bc #45) A - Dylans loves numbers (hdu 5272)

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

快要炸了..

tle成狗

因为是tle,看了下自己没有写cin cout,估计就是算法的问题…

我是先存了二进制的每一位到数组,然后扫一遍…

嗯,这都tle…

那我不存不扫,直接记录当前二进制位和之前二进制位..

logn的复杂度总可以了吧啊?

还TLE……….

嗯,其实已经发现 n是小于等于1e18的,没开long long

但是一位没开long long 会是wa…就没理…

之后实在黔驴技穷,改了下,竟然过了…

然后想明白了.

因为存二进制的时候有一个while

没开long long 的话就炸了,不知道读进去的是什么,while就出不来,于是就tle了.T T

果然太年轻.

 1
 2
 3
 4    /*************************************************************************
 5    	> File Name: code/bc/#45/1001.cpp
 6    	> Author: 111qqz
 7    	> Email: rkz2013@126.com
 8    	> Created Time: 2015年07月29日 星期三 13时25分01秒
 9     ************************************************************************/
10
11    #include<iostream>
12    #include<iomanip>
13    #include<cstdio>
14    #include<algorithm>
15    #include<cmath>
16    #include<cstring>
17    #include<string>
18    #include<map>
19    #include<set>
20    #include<queue>
21    #include<vector>
22    #include<stack>
23    #define y0 abc111qqz
24    #define y1 hust111qqz
25    #define yn hez111qqz
26    #define j1 cute111qqz
27    #define tm crazy111qqz
28    #define lr dying111qqz
29    using namespace std;
30    #define REP(i, n) for (int i=0;i<int(n);++i)
31    typedef long long LL;
32    typedef unsigned long long ULL;
33    const int inf = 0x7fffffff;
34    const int N=1E3+5;
35    int a[N];
36    LL n,nn;
37    int main()
38    {
39        int T;
40        cin>>T;
41        while (T--)
42        {
43    	scanf("%lld",&n);
44    	nn = n ;
45    	int k = 0;
46    	while (nn)
47    	{
48    	    k++;
49    	    a[k]=nn&1;
50    	    nn = nn >>1;
51    	}
52    	int ans = 0;
53    //	for ( int i = 1 ; i <= k ; i++ )
54    //	    cout<<a[i]<<endl;
55    	for ( int i = 1 ; i <= k ; i++ )
56    	{
57    	    if (a[i]==1&&a[i-1]==0)
58    		ans++;
59    	}
60    	printf("%d\n",ans);
61        }
62    	return 0;
63    }

Related

cf 443B Kolya and Tandem Repeat

·1 min
B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

poj 3279 Fliptile (搜索..暴力?)

·2 mins
http://poj.org/problem?id=3279 反转类问题. 有N*M个方格,每个上面有数字0或者1 操作一个方格,这个方格即其相邻的四个方格(有公共边)会改变状态(由0变1或者由1变0)

codeforces 548B Mike and Fun

·1 min
http://codeforces.com/problemset/problem/548/B 比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。