# bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数

## 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

code：
 1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 using namespace std;
7 char ch;
8 bool ok;
10     ok=0;
11     for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
12     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
13     if (ok) x=-x;
14 }
15 const int maxn=33;
16 int l,r,c[maxn][maxn],cnt[maxn],a[maxn];
17 void init(){
18     for (int i=0;i<=32;i++) c[i][0]=1;
19     for (int i=1;i<=32;i++) for (int j=1;j<=i;j++) c[i][j]=c[i-1][j-1]+c[i-1][j];
20     cnt[0]=1;
21     for (int i=1;i<=32;i++) for (int j=i-1,k=1;j>=k;j--,k++) cnt[i]+=c[i-1][j];
22     for (int i=1;i<=32;i++) cnt[i]+=cnt[i-1];
23 }
24 int calc(int n){
25     int t=n,len=0,ans=0,tmp0=0,tmp1=0;
26     memset(a,0,sizeof(a));
27     while (t) a[++len]=t&1,t>>=1;
28     for (int i=len;i;i--){
29         if (i==len) ans+=cnt[i-1];
30         else if (a[i]){for (int j=i-1;j+tmp0+1>=tmp1+i-1-j;j--) ans+=c[i-1][j];}
31         if (a[i]) tmp1++; else tmp0++;
32     }
33     return ans;
34 }
35 int main(){
36     init();
40 }