BZOJ1662: [Usaco2006 Nov]Round Numbers

1662: [Usaco2006 Nov]Round Numbers

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 147  Solved: 84
[Submit][Status][Discuss]

Input

* Line 1: 两个用空格分开的整数，分别表示Start 和 Finish。

Output

* Line 1: Start..Finish范围内round numbers的个数

2 12

Sample Output

6

2 10 1x0 + 1x1 ROUND
3 11 0x0 + 2x1 NOT round
4 100 2x0 + 1x1 ROUND
5 101 1x0 + 2x1 NOT round
6 110 1x0 + 2x1 NOT round
7 111 0x0 + 3x1 NOT round
8 1000 3x0 + 1x1 ROUND
9 1001 2x0 + 2x1 ROUND
10 1010 2x0 + 2x1 ROUND
11 1011 1x0 + 3x1 NOT round
12 1100 2x0 + 2x1 ROUND

Source

----------------------------------------------------------------------------------------------------------
UPD：以上内容实属脑残。。。

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 500+100
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define mod 1000000007
23 using namespace std;
25 {
26     ll x=0,f=1;char ch=getchar();
27     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
28     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
29     return x*f;
30 }
31 ll c[50][50],cc[50][50],s[2],a[50],l,r;
32 ll work(ll n)
33 {
34     a[0]=0;
35     while(n)a[++a[0]]=n&1,n>>=1;
36     ll t=0;
37     for1(i,a[0]-1)
38      {
39          int x=i;
40         if(x&1)x=(x>>1)+1;else x>>=1;
41          t+=cc[i-1][x];
42      }
43     s[0]=0;s[1]=1;
44     for3(i,a[0]-1,1)
45     {
46         if(a[i])
47          {
48              int x=s[1]-s[0]-1+i-1;
49              if(x<=0)x=0;
50              else if(x&1)x=(x>>1)+1;
51                 else x>>=1;
52              t+=cc[i-1][x];
53          }
54         s[a[i]]++;
55     }
56     if(s[0]>=s[1])t++;
57     t++;
58     return t;
59 }
60 int main()
61 {
62     freopen("input.txt","r",stdin);
63     freopen("output.txt","w",stdout);
64     cc[0][0]=c[0][0]=1;
65     for1(i,35)
66      {
67          c[i][0]=c[i][i]=1;
68          for1(j,i-1)c[i][j]=c[i-1][j]+c[i-1][j-1];
69          cc[i][i]=1;
70          for3(j,i-1,0)cc[i][j]=cc[i][j+1]+c[i][j];
71      }
75 }