标签:des style blog http java color os strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15323 Accepted Submission(s):
4353
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 struct node 7 { 8 int a,b; 9 } t[500010]; 10 int cmp(struct node x,struct node y) 11 { 12 if(x.a!=y.a) 13 return x.a<y.a; 14 } 15 int findindex(int *b,int len,int w) 16 { 17 int left=0,right=len-1,mid; 18 while(left<=right) 19 { 20 mid=left+(right-left)/2; 21 if(b[mid]<w) 22 left=mid+1; 23 else if(b[mid]>w) 24 right=mid-1; 25 else 26 return mid; 27 } 28 return left; 29 } 30 int bb[500010]; 31 int main() 32 { 33 int n,i,j,len,pos,num=1; 34 while(scanf("%d",&n)!=EOF) 35 { 36 for(i=0; i<n; i++) 37 scanf("%d%d",&t[i].a,&t[i].b); 38 len=1; 39 sort(t,t+n,cmp); 40 bb[0]=t[0].b; 41 pos=0; 42 for(i=1; i<n; i++) 43 if(t[i].b>bb[len-1]) 44 bb[len++]=t[i].b; 45 else 46 { 47 pos=findindex(bb,len,t[i].b); 48 bb[pos]=t[i].b; 49 } 50 printf("Case %d:\n",num++); 51 if(len==1) 52 printf("My king, at most 1 road can be built.\n\n"); 53 else 54 printf("My king, at most %d roads can be built.\n\n",len); 55 } 56 return 0; 57 }
标签:des style blog http java color os strong
原文地址:http://www.cnblogs.com/lxm940130740/p/3870138.html