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就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...
随机推荐
- 使用Topshelf管理Windows服务
目的:以控制台方式开发Windows服务程序,调试部署方便. https://www.cnblogs.com/itjeff/p/8316244.html https://www.cnblogs.com ...
- sql server2016里面的json功能 - 转
测试一下基本的,从查询结果里面构造一个json 的格式 create table t1(ID int identity,name nvarchar(50),Chinese int ,Math int) ...
- kafka学习2:kafka集群安装与配置
在前一篇:kafka学习1:kafka安装 中,我们安装了单机版的Kafka,而在实际应用中,不可能是单机版的应用,必定是以集群的方式出现.本篇介绍Kafka集群的安装过程: 一.准备工作 1.开通Z ...
- Python3.x:Selenium+PhantomJS爬取带Ajax、Js的网页及获取JS返回值
前言 现在很多网站的都大量使用JavaScript,或者使用了Ajax技术.这样在网页加载完成后,url虽然不改变但是网页的DOM元素内容却可以动态的变化.如果处理这种网页是还用requests库或者 ...
- R实战 第十篇:列联表和频数表
列联表是观测数据按两个或更多属性(定性变量)分类时所列出的频数分布表,它是由两个以上的变量进行交叉分类的频数分布表.交互分类的目的是将两变量分组,然后比较各组的分布状况,以寻找变量间的关系. 按两个变 ...
- c++对象模型-对象模型
1:简单对象模型 1>介绍:每个成员都使用一个指针指向真正的成员.所以对象 的大小很好确定,就是成员数*指针大小. 2>用途:成员函数就是使用这个模型的 3>图: 4>加上继承 ...
- WEB 小案例 -- 网上书城(四)
针对于这个小案例我们今天讲解结账操作,也是有关这个案例的最后一次博文,说实话这个案例的博文写的很糟糕,不知道该如何去表述自己的思路,所以内容有点水,其实说到底还是功力不够. 处理思路 点击结账,发送结 ...
- 新人入坑Redis必会的吐血总结
新人入坑Redis必会的吐血总结 一.什么是Redis Redis是一个使用C语言开发的开源的高性能的key-value存储系统,我们可以把它近似理解为Java Map.简单来讲,Redis是一种NO ...
- better-scroll的参数和方法
格式:let obj = new BScroll(object,{[option1,],.,.}); 注意,如果在某一个组件内创建了一个BScroll的实例,在组件生命周期结束前要注意调用destro ...
- 快速搭建BIND服务,并实现解析
公司有测试需求,当连接一个网络后自动会进入产品的测试环境,所以搭建了一个DNS解析服务,来完成此需求. 参考:http://blog.chinaunix.net/uid-30149335-id-506 ...