Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
奇怪的问题AC代码如下:(注释的那行不会影响结果,但是如果不注释就会出错。。。。求解脱!!!) #include<cstdio> int c[33][33],dp[33][33]; void init() { int i,j; c[0][0]=1; for(i=1;i<=32;i++) { c[i][0]=1; for(j=1;j<=i;j++) c[i][j]=c[i-1][j-1]+c[i-1][j]; dp[i][0]=1; ////////////////for(j=1;j<=i;j++) dp[i][j]=dp[i-1][j]+dp[i][j-1]; } } int length(int n) { int ret=0; while(n) { n>>=1; ret++; } return ret; } int cnt(int n) { if(n<=1) return 0; int ans=0,len=length(n),i,j,n2; int nu=(len>>1)+(len&1),one=1,zero=0; for(i=2;i<len;i++) { n2=(i>>1)+(i&1); for(j=n2;j<i;j++) ans+=c[i-1][j]; } for(i=2;i<=len;i++) { if((n&(1<<(len-i)))==0){zero++;continue;} for(j=nu-zero-1;j+i<=len;j++) ans+=c[len-i][j]; one++; } return ans; } int main() { init(); int a,b; scanf("%d%d",&a,&b); printf("%d\n",cnt(b+1)-cnt(a)); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator