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 |
为什么总是超时,那位大牛帮忙看哈,谢谢了~_~//ID2657_poj //#include<iostream> #include<memory.h> #include<stdio.h> //using namespace std; void main() { bool b[1010],flag; int n,z,m,tamp,i,j; int t,span; while(scanf("%d %d %d",&n,&z,&m)!=EOF) { if(0==m) { //cout<<"1"<<endl; printf("1\n"); continue; } if(1==z) printf("0\n"); memset(b,false,sizeof(b)); for(i=0;i<m;i++) { scanf("%d",&tamp); b[tamp]=true; } flag=false; span=t=1; for(span=1;span<z;span++) { for(j=1;i<=n;j++) { t=t+span; if(b[t]) { // span++; t=1; // continue; break; } else if(t==z) { // cout<<span<<endl; flag=true; break; } else { if(t>n) t=t-n; // t=(t+span)%n; // if(0==t) // t=1; } } if(flag) break; } // cout<<span<<endl; printf("%d\n",span); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator