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 |
me tooIn Reply To:在某个状态,取出下次访问时间最晚的元素,替换 Posted by:zymx at 2005-10-30 16:54:46 #include <stdio.h> int main() { int i,j,k,n,t,p,q,max; int driver[11]; int req[101]; int insert; scanf("%d",&t); for(;t>0;t--){//case number scanf("%d%d",&k,&n); if(k>=n) {//driver number biger or equal than dvd for(i=0;i<n;i++){ scanf("%d",&j); } printf("%d\n",n); continue; } for(i=0;i<n;i++){ scanf("%d",&req[i]); } for(i=0;i<k;i++){ driver[i]=req[i]; } insert=k; //there should be at least k insertions for(i=k;i<n;i++){ for(j=0;j<k;j++){ if(req[i]==driver[j])break; } if(j<k)continue; //needn't to insert max=-1; for(j=0;j<k;j++) { for(p=i+1;p<n;p++) { if(driver[j]==req[p])break; } if(max<p){ //find the last that need to insert max=p; q=j; } } ++insert; driver[q]=req[i]; } printf("%d\n",insert); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator