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 |
这题有什么好算法吗?本人居然512ms……各位大牛又没有什么更好的方法,望不吝赐教哦~ #include<iostream> using namespace std; int main() { int claim,zib;cin>>claim>>zib; int reader; bool* occur = new bool [zib+1]; memset(occur,false,(zib+1)*sizeof(bool)); int remain = zib,count = 1; bool oddflag = false; while(claim != 0) { cin>>reader; if(oddflag == occur[reader]) { remain--; occur[reader] = !occur[reader]; } if(remain == 0) { remain = zib; count++; oddflag = !oddflag; } claim--; } cout<<count<<endl; delete [] occur; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator