hdu 1025 Constructing Roads In JGShining's Kingdom LIS最长上升序列
2017-09-07 17:57
525 查看
传送门http://acm.hdu.edu.cn/showproblem.php?pid=1025
裸LIS, 不多说 (nlogn)
binary_sch 二分查找
road == 1 的时候没有复数 ‘s’.
2017-09-07
裸LIS, 不多说 (nlogn)
binary_sch 二分查找
road == 1 的时候没有复数 ‘s’.
#include <stdio.h> #include <iostream> #include <cmath> #include <algorithm> using namespace std; const int MAX = 5e5+5; const int INF = 1 << 32 - 1; int ary[MAX], dp[MAX], a, b, n, T; int binary_sch(int l, int r, int num) { if (r - l == 1) return l; int tmp = (l+r) >>1; //这里被学长骂了, 原来写的是 (l+r)/2 if (dp[tmp] == num) return tmp - 1; if (dp[tmp] > num) return binary_sch(l, tmp, num); return binary_sch(tmp, r, num); } void getin() { for (int i = 0; i < n; ++i) { scanf("%d%d", &a, &b); ary[a] = b, dp[i] = INF; } dp[0] = 0, dp = INF, dp[n+1] = INF; } void judge() { for (int i = 1; i <= n; ++i) { int tmp = binary_sch(0, n, ary[i]); dp[tmp+1] = ary[i]; } int ans = 0; while (dp[ans++] != INF) {;} printf ("Case %d:\n", T); if(ans-2 == 1) printf("My king, at most 1 road can be built.\n\n"); else printf ("My king, at most %d roads can be built.\n\n", ans-2); return ; } int main() { for (T = 1; scanf("%d", &n) == 1; ++T) { getin(); judge(); } return 0; }
2017-09-07
相关文章推荐
- HDU 1025-Constructing Roads In JGShining's Kingdom(最长上升子序列 NlogN复杂度)
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列的长度)
- 最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP,LIS最长上升子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom(LIS最长上升子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom (简单dp, 最长上升子序列LIS)
- hdu 1025 Constructing Roads In JGShining's Kingdom【即求最长上升子序列】
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升序列
- HDU 1025(Constructing Roads In JGShining's Kingdom)最长不降子序列nlogn
- hdu 1025 Constructing Roads In JGShining's Kingdom (最长上升子序列)
- HDU 1025 - Constructing Roads In JGShining's Kingdom(最长上升子序列)
- HDU 1025 A - Constructing Roads In JGShining's Kingdom(最长上升子序列)
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升序列nlogn
- hdu 1025 Constructing Roads In JGShining's Kingdom--最长上升子串(时间优化)
- 【DP】HDU 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列
- HDU - 1025 Constructing Roads In JGShining's Kingdom (nlogn 最长上升子序列)
- 杭电ACM OJ 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列 O(nlogn)算法详解+回溯暴力解决+动态规划dp优雅解决
- 暑期dp46道(16)hdoj 1025 Constructing Roads In JGShining's Kingdom最长上升子序列(二分)
- HDU - 1025 Constructing Roads In JGShining's Kingdom(最长单调子序列 nlogn)
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)