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 |
Re:开大数组,利用数组设用过的数值为1,避免查找。。这些都用了。可还是运行错误。给个可行方案,谢谢了大侠。。In Reply To:开大数组,利用数组设用过的数值为1,避免查找。。这些都用了。可还是运行错误。给个可行方案,谢谢了大侠。。 Posted by:jjh at 2005-08-05 15:55:03 #include<stdio.h> void main() { int m[500001]; bool n[5000000]; long i,j; m[0]=0; n[0]=true; for(i=0;i<5000000;i++) n[i]=false; for(i=1;i<=500000;i++) { if((m[i-1]-i)>0&&n[m[i-1]-i]==false) {m[i]=m[i-1]-i; n[m[i]]=true;} else {m[i]=m[i-1]+i; n[m[i]]=true;} } while(1) { scanf("%ld",&j); if(j==-1) break; printf("%ld\n",m[j]); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator