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 |
哎,此题用LIST感觉还不是那么水呃,一次A过,STL太赞了。当然,O可没有随随便便写出了就,俺可是用心了的(附代码,供STL初学者参考)#include<iostream> #include<list> #include<algorithm> using namespace std; int main() { int m,n,k,i,j; int v,kk,tmp,sum,summ; list<int>pzj; list<int>::iterator ita; list<int>::iterator itb; scanf("%d",&m); while(m--) { sum=0; summ=0; pzj.clear(); scanf("%d%d",&n,&k); for(i=0;i<n;i++) { scanf("%d",&v); pzj.push_back(v); if(i==k) kk=v; } bool cs=0; k++; while(find(pzj.begin(),pzj.end(),kk)!=pzj.end()) { summ++; cs=0; tmp=pzj.front(); for(i=9;i>tmp;i--) if(find(pzj.begin(),pzj.end(),i)!=pzj.end()) { cs=1; break; } if(cs) { pzj.pop_front(); pzj.push_back(tmp); if(summ==k)//防止数组中重复出现目标数字,要记录需要打印的数字的编号,并不时比较打印的是否是目标数字的标号 { k=n-sum; summ=0; } } else { pzj.pop_front(); sum++; if(summ==k) break; } } printf("%d\n",sum); } return false; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator