标签:des style blog http java color
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 659 Accepted Submission(s): 207
1 #include <iostream> 2 #include <stdio.h> 3 #include <algorithm> 4 #include <math.h> 5 #include <string.h> 6 #include <set> 7 #include <queue> 8 using namespace std; 9 typedef struct abcd 10 { 11 int p,last; 12 } abcd; 13 abcd a[110000]; 14 int flag[110000]; 15 int main() 16 { 17 int c,n,b,i,j,now,ans; 18 while(~scanf("%d%d%d",&c,&n,&b)) 19 { 20 for(i=0; i<n; i++)flag[i]=110000; 21 for(i=0; i<b; i++) 22 scanf("%d",&a[i].p); 23 for(i=b-1; i>=0; i--) 24 { 25 a[i].last=flag[a[i].p]; 26 flag[a[i].p]=i; 27 } 28 ans=now=0; 29 memset(flag,0,sizeof(flag)); 30 priority_queue<pair<int,int> > q; 31 while(!q.empty())q.pop(); 32 for(i=0; i<b; i++) 33 { 34 if(now<c) 35 { 36 if(flag[a[i].p]) 37 { 38 q.push(make_pair(a[i].last,a[i].p)); 39 } 40 else 41 { 42 flag[a[i].p]=1; 43 now++; 44 ans++; 45 q.push(make_pair(a[i].last,a[i].p)); 46 } 47 } 48 else 49 { 50 if(flag[a[i].p]) 51 { 52 q.push(make_pair(a[i].last,a[i].p)); 53 } 54 else 55 { 56 ans++; 57 while(flag[q.top().second]==0)q.pop(); 58 pair<int,int >t=q.top(); 59 q.pop(); 60 flag[a[i].p]=1; 61 flag[t.second]=0; 62 q.push(make_pair(a[i].last,a[i].p)); 63 } 64 } 65 } 66 cout<<ans<<endl; 67 } 68 }
Operating system hdu 2835 OPT,布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/ERKE/p/3837525.html