hdu 1025
Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource.
With the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they're unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don't wanna build a road with other poor ones, and rich ones also can't abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one.
Rich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II.
The location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1, Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities ... And so as the poor ones.
But as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads.
For example, the roads in Figure I are forbidden.
In order to build as many roads as possible, the young and handsome king of the kingdom - JGShining needs your help, please help him. ^_^
You should tell JGShining what's the maximal number of road(s) can be built.
1 2
2 1
3
1 2
2 3
3 1
My king, at most 1 road can be built.
Case 2:
My king, at most 2 roads can be built.
Huge input, scanf is recommended.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
const int MAX=1e5+;
#define INF 0x7fffffff
#define ll long long
#define FOR(i,n) for(i=1;i<=n;i++)
#define mst(a) memset(a,0,sizeof(a))
//struct num{int a,b,c;}a[1005];
int dp[],road[];
int main()
{
int m,i,a,b;
int c = ;
while(scanf("%d",&m)!=EOF){
fill(dp,dp+m,INF);
for(i=;i<m;i++){
scanf("%d%d",&a,&b);
road[a] = b;
}
for(i=;i<=m;i++){
*lower_bound(dp,dp+m,road[i])=road[i];
}
int len = lower_bound(dp,dp+m,INF)-dp;
if(len==)
{
cout<<"Case "<<c++<<":"<<endl;
cout<<"My king, at most 1 road can be built."<<endl;
}
else
{
cout<<"Case "<<c++<<":"<<endl;
cout<<"My king, at most "<<len<<" roads can be built."<<endl;
}
cout<<endl;
}
return ;
}
hdu 1025的更多相关文章
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...
- HDU 1025 DP + 二分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)
http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Des ...
- hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】
主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...
- Hdu 1025(LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu 1025 lis 注意细节!!!【dp】
感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...
随机推荐
- 随笔一个dom节点绑定事件
以下利用jquery说明: js中,给一个dom节点绑定事件再平常不过了.这里说下,如果dom经常发生变化的话,给这个dom绑定事件的情况. 比如代码如下: li的节点,绑定了事件:点击会打出来里头的 ...
- 【php增删改查实例】第十五节 - 用户管理模块(删除确认)
假如有一天,用户找到你,说万一不小心手一抖,就点击了删除用户,不太好.能不能再误点的时候,再给个确认框,让用户进行二次确认. OK,用户是上帝.这边我们可以考虑用confirm方法进行开发. 参考代码 ...
- 2.RapidIO串行物理层的包与控制符号
转自https://www.cnblogs.com/liujinggang/p/9932150.html 一.RapidIO串行物理层背景介绍 上篇博文提到RapidIO的物理层支持串行物理层与并行物 ...
- JVM规范系列:总结
我们花了几天的时间来阅读<Java虚拟机规范>,了解要实现一个虚拟机应该包括什么内容.通过这么一次阅读,我们大致了解了虚拟机规范的内容. 第1章.对Java虚拟机进行了一些简单的介绍. 第 ...
- 谈谈css伪类与伪元素
前端er们大都或多或少地接触过CSS伪类和伪元素,比如最常见的:focus.:hover以及<a>标签的:link.:visited等,伪元素较常见的比如:before.:after等. ...
- 浅谈移动端设备标识码:DeviceID、IMEI、IDFA、UDID和UUID
---恢复内容开始--- 转:https://www.jianshu.com/p/38f4d1a4763b [心路历程] 最近刚好在思考工作中统计数据所用的标识码产生的数据误差到底有多大,借此机会几番 ...
- 使用阿里云cli管理安全组
相比于python SDK方式,阿里云基于GO SDK开发了一整套CLI工具,可以通过调用RPC API来管理云资源,对编程能力不够的人来说是个福音. 而且,阿里云CLI的文档比SDK的文档更加全面, ...
- centos7下部署iptables环境纪录(关闭默认的firewalle)
CentOS7默认的防火墙不是iptables,而是firewall.由于习惯了用iptables作为防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables ...
- linux-文件流4种读取方式
第二种方式 第三种 第四种: 小括号在管道符的右边开辟了两个子进程 大括号在管道符的右边开辟了一个子进程, export 用来导出子进程的 num 还可以借助外部文件进行 七步扩展:
- github链接与心得体会
https://github.com/wangyuefang/test 第一次使用github,我觉得github是一个非常人性化的软件,使用起来很方便.而且可以把GitHub作为免费的远程仓库,如果 ...