Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

me too

Posted by xiaol at 2005-11-27 19:45:56 on Problem 2698
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator