码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1025 LIS nlogn复杂度

时间:2015-07-26 17:31:20      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:dp

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector>

using namespace std;
#define INF 0x4fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
struct node{
	int x,y;
	bool operator<(const node& a)const{
		return x < a.x && y <= a.y;
	}
};
int cmp(node a,node b){
	return a.x < b.x;
}
node dp[500005];
node a[500005];
int main(){
	int n;
	int T = 1;
	while(cin >> n){
		for(int i = 0;i < n;i++){
			scanf("%d%d",&a[i].x,&a[i].y);
		}
		for(int i = 0;i <= n;i++){
			dp[i].x = INF;
			dp[i].y = INF;
		}
		sort(a,a+n,cmp);
		for(int i = 0;i < n;i++){
			*lower_bound(dp,dp+n,a[i]) = a[i];
		}
		node ans;
		ans.x = INF;
		ans.y = INF;
		int q = lower_bound(dp,dp+n,ans)-dp;
		if(q == 1)
			printf("Case %d:\nMy king, at most %d road can be built.\n\n",T++,q);
		else
			printf("Case %d:\nMy king, at most %d roads can be built.\n\n",T++,q);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu 1025 LIS nlogn复杂度

标签:dp

原文地址:http://blog.csdn.net/qq_24667639/article/details/47068465

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!