标签:
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 5 using namespace std; 6 7 const int maxn=500000+5; 8 9 struct Node 10 { 11 int a,b; 12 }node[maxn]; 13 14 int dp[maxn]; 15 16 bool cmp(Node x,Node y) 17 { 18 if(x.a==y.a) 19 return x.b<y.b; 20 return x.a<y.a; 21 } 22 23 int Search(int num,int low,int high) 24 { 25 int mid; 26 27 while(low<=high) 28 { 29 mid=(low+high)/2; 30 31 if(num>=dp[mid]) 32 low=mid+1; 33 else 34 high=mid-1; 35 } 36 37 return low; 38 } 39 40 int DP(int n) 41 { 42 int len=1; 43 44 dp[len]=node[1].b; 45 46 for(int i=2;i<=n;i++) 47 { 48 if(node[i].b>dp[len]) 49 { 50 len++; 51 dp[len]=node[i].b; 52 } 53 else 54 { 55 int pos=Search(node[i].b,1,len); 56 57 dp[pos]=node[i].b; 58 } 59 } 60 return len; 61 } 62 63 int main() 64 { 65 int n; 66 67 int cas=1; 68 69 while(scanf("%d",&n)!=EOF) 70 { 71 for(int i=1;i<=n;i++) 72 scanf("%d%d",&node[i].a,&node[i].b); 73 74 sort(node+1,node+n+1,cmp); 75 76 int len=DP(n); 77 78 printf("Case %d:\n",cas++); 79 80 81 82 //超级坑,len<=1的时候是road 83 //len>1的时候road为复数,是roads 84 85 86 87 if(len<=1) 88 printf("My king, at most %d road can be built.\n\n",len); 89 else 90 printf("My king, at most %d roads can be built.\n\n",len); 91 92 } 93 return 0; 94 }
HDU 1025 Constructing Roads In JGShining's Kingdom LIS 简单题 好题 超级坑
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4452184.html