HDU 1025 Constructing Roads In JGShining's Kingdom
来源:互联网 发布:数据化分析 编辑:程序博客网 时间:2024/05/19 14:36
题目链接
题目大意为poor城市要搭建路去rich城市
路不能交叉,而且保证poor城市和rich城市不会有相同的,一开始这里坑了一把
很明显LIS最长子序列问题,但是,题目输出很坑
如果只能搭建一条路的话,输出时road不能加s
我一直wa,调程序的bug。
一定的记住要看清题意。
直接用二分来优化。
用到了LIS(nlogn)算法。
请点这题,很好理解上述算法
如果不想看就点这里LIS(nlogn)算法
下面是代码
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int a[500010];int d[500010];int n;int main(){ int kase = 1; while(~scanf("%d",&n)){ for(int i=0,p,r;i<n;i++){ scanf("%d%d",&p,&r); a[p] = r; } int len = 1; memset(d,0,sizeof(d)); d[1] = a[1]; for(int i=2;i<=n;i++){ int w = lower_bound(d+1,d+len+1,a[i]) - (d+1); if(w==len){ len++; d[w+1] = a[i]; }else d[w+1] = a[i]; //printf("%d w %d len %d\n",w,len,d[w+1]); } 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;}/*51 42 33 54 15 271 12 73 44 65 56 27 3*/
此题很水,但是自己还是粗心。
1 0
- hdu Constructing Roads In JGShining's Kingdom
- hdu 1025Constructing Roads In JGShining's Kingdom(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
- Hdu 1025 Constructing Roads In JGShining's Kingdom
- 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
- hdu 1025 Constructing Roads In JGShining's Kingdom(LIS)
- HDU 1025 Constructing Roads In JGShining's Kingdom
- 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
- hdu 1025 Constructing Roads In JGShining's Kingdom
- hdu 1025 Constructing Roads In JGShining's Kingdom (LIS)
- HDU - 1025 Constructing Roads In JGShining's Kingdom
- HDU 1025 Constructing Roads In JGShining's Kingdom
- 多校训练-Bubble Sort(树状数组+离散化)
- 关于tableview 编辑下多选择处理
- HDU 3038 How Many Answers Are Wrong
- mac brew 安装使用
- 【指导】SonarQube 部署说明
- HDU 1025 Constructing Roads In JGShining's Kingdom
- web 开发一个能进行人员管理(查询,删除,添加)的应用
- //切割字符串
- vector的push_back
- 谈谈C里面的指针之二【指针的加减法】
- 使用SQLyog将sqlserver的数据及表结构迁移到mysql中
- php基础知识
- 每日总结 2016年七月28日一个地方的异常会引发其他地方的异常
- Docker 与 PAAS