hdu1025(nlogn的求非递减子序列)
来源:互联网 发布:淘宝外卖要实体店吗 编辑:程序博客网 时间:2024/06/15 00:31
/*****************************************Author :Crazy_AC(JamesQi)Time :2015File Name :*****************************************/// #pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <algorithm>#include <iomanip>#include <sstream>#include <string>#include <stack>#include <queue>#include <deque>#include <vector>#include <map>#include <set>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <limits.h>using namespace std;#define MEM(a,b) memset(a,b,sizeof a)#define pk push_backtemplate<class T> inline T Get_Max(const T&a,const T&b){return a < b?b:a;}template<class T> inline T Get_Min(const T&a,const T&b){return a < b?a:b;}typedef long long ll;typedef pair<int,int> ii;const int inf = 1 << 30;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 500007;int city[N];int dp[N];int Search(int* dp,int len,int num){int low = 1,high = len;while(low <= high){int mid = (low + high) >> 1;if (num == dp[mid]) return mid;if (dp[mid] < num) low = mid + 1;else high = mid - 1;}return low;}int main(){// ios::sync_with_stdio(false);// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);int n;int kase = 1;while(~scanf("%d",&n)){int a,b;for (int i = 1;i <= n;++i){scanf("%d%d",&a,&b);city[a] = b;}dp[0] = -1;dp[1] = city[1];int len = 1;for (int i = 1;i <= n;i++){if (dp[len] < city[i]) dp[++len] = city[i];else{int j = Search(dp,len,city[i]);dp[j] = city[i];}}printf("Case %d:\n",kase++);if (len == 1) printf("My king, at most %d road can be built.\n\n",len);else printf("My king, at most %d roads can be built.\n\n",len);}return 0;}
0 0
- hdu1025(nlogn的求非递减子序列)
- 计蒜客 求数组的最长递减子序列(nlogn+路径打印)
- 最长非递减子序列的应用
- 求数组的最长递减子序列
- hdu1025!求最长上升子序列的另种方法!!!!
- HDU1025 最长上升子序列(nlogn算法) DP
- hdu1025 最长上升子序列 O(nlogn)优化版
- 应用递推的方法求最长非递减子序列的长度
- (NYoj 236)心急的C小加 --求所有的非递减最长子序列
- 最长非递减子序列
- 求最长递减子序列
- HDU1025 nlogn的LIS
- 最大递增/递减/非递增/非递减子序列的长度(二分优化)
- 求一个数组的最长递减子序列
- 求一个数组的最长递减子序列
- 求一个数组的最长递减子序列
- 求一个数组的最长递减子序列
- coding - 求数组的最长递减子序列
- (四)linux下配置jenkins--构建一个自由风格的项目
- 跨应用Service
- url传字符串的时候,如果字符串中有“/”,则可能会影响到域名解析
- 用深度遍历dfs判断一个有向图是否有环
- 提高MySQL大数据量查询的速度
- hdu1025(nlogn的求非递减子序列)
- 宣告主权
- COCI CONTEST #3 29.11.2014 HONI
- 查看端口被占用
- 虚幻引擎3命令行参数
- iOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- [LeedCode OJ]#160 Intersection of Two Linked Lists
- 启用mysqli扩展模块
- IP地址的分类——a,b,c 类是如何划分的