标签:
Constructing Roads In JGShining‘s Kingdom3 1
#include <stdio.h> #include <algorithm> using namespace std; int p[500100]; int b[500100]; int Research(int right,int num) { int middle,left=1; while(left<=right) { middle=(left+right)/2; if(num>=b[middle]) left=middle+1; else right=middle-1; } return left; } int main() { int n,cas=1; while(~scanf("%d",&n)) { int a,c; for(int i=1;i<=n;i++) { scanf("%d%d",&a,&c); p[a]=c; } b[1]=p[1]; int cnt=1; for(int i=2;i<=n;i++) { if(p[i]>b[cnt]) b[++cnt]=p[i]; else { int pos=Research(cnt,p[i]); b[pos]=p[i]; } } printf("Case %d:\n",cas++); printf("My king, at most %d road",cnt); if(cnt!=1) printf("s"); printf(" can be built.\n\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/a73265/article/details/48036689