hdu 1025 lis 注意细节!!!【dp】
感觉这道题浪费了我半个小时的生命。。。。。。哇靠!原来输出里面当len=1时是road否则是roads!!!
其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列。我用结构体记录要连线的两个city,对一个数组排序再求相应的另一个数组lis。 开始WA还以为我写错了, 造了数据测一下没错啊。。。又想是不是情况没考虑全,比如一个城市可以连好多城市,好多城市可以连一个城市???巴拉巴拉。。。后来发现只可以一对一啊。。。。死在这种细节上真的是欲哭无泪。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN = ;
struct Node{
int p,r;
};
Node a[MAXN];
int dp[MAXN],t[MAXN];
int len=; bool cmp(Node a,Node b)
{
if(a.p==b.p)
return a.r<b.r;
return a.p<b.p;
} int bin_search(int key)
{
int low,high,mid;
low=,high=len;
while(low<high)
{
mid=(low+high)>>;
if(t[mid]>=key)
high=mid;
else low=mid+;
}
return low;
} int main()
{
int N;
int cas=;
while (scanf("%d", &N) == )
{
for (int i = ; i < N; i++) {
scanf("%d%d",&a[i].p,&a[i].r);
dp[MAXN]=INF;
}
sort(a,a+N,cmp);
len=;
t[]=a[].r;
for(int i=;i<N;i++){
if(a[i].r>t[len-])
t[len++]=a[i].r;
else{
int pos=bin_search(a[i].r);
t[pos]=a[i].r;
}
}
if(len==) printf("Case %d:\nMy king, at most %d road "
"can be built.\n\n",cas++,len);
else
printf("Case %d:\nMy king, at most %d roads "
"can be built.\n\n",cas++,len);
}
return ;
}
hdu 1025 lis 注意细节!!!【dp】的更多相关文章
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- HDU 1025 (LIS+二分) Constructing Roads In JGShining's Kingdom
这是最大上升子序列的变形,可并没有LIS那么简单. 需要用到二分查找来优化. 看了别人的代码,给人一种虽不明但觉厉的赶脚 直接复制粘贴了,嘿嘿 原文链接: http://blog.csdn.net/i ...
- Hdu 1025(LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- Constructing Roads In JGShining's Kingdom(HDU 1025 LIS nlogn方法)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 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(二维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+二分)
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...
- HDU 4521 间隔》=1的LIS 线段树+dp
九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11991119 题意: n个数 d个距离 下面n个数的序列,求序列中的最长单调递增 ...
- hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- 【html、CSS、javascript-13】前端框架Bootstrap
1.Bootstrap前端框架:包含css样式.js插件.图标等 http://www.bootcss.com/ 2.Font Awesome:非常全的图标大全 https://fontawesome ...
- CodeChef--EQUAKE
题目链接 Earthquake in Bytetown! Situation is getting out of control! All buildings in Bytetown stand on ...
- Neo4j属性图模型简单介绍
本文主要是对Neo4j属性图模型简单的介绍. Neo4j是什么? Neo4j是一款是由java语言实现的图数据库,图形数据库将数据以图的数据结构进行存储和管理,并且能够以高度可问的方式优雅地表示任何种 ...
- CHARINDEX函数
CHARINDEX函数返回字符或者字符串在另一个字符串中的起始位置.CHARINDEX函数调用方法如下: CHARINDEX ( expression1 , expression2 [ , st ...
- python基础--字符编码以及文件操作
字符编码: 1.运行程序的三个核心硬件:cpu.内存.硬盘 任何一个程序要是想要运算,肯定是先从硬盘加载到当前的内存中,然后cpu根据指定的指令去执行操作 2.python解释器运行一个py文件的步骤 ...
- Oracle 优化效率
一.链接: ORACLE多表查询优化 oracle的 分表 详解 -----表分区 Oracle数据库查询优化方案(处理上百万级记录如何提高处理查询速度) 数据库SQL优化大总结之 百万级数据库优化方 ...
- 【CodeVS】1023 GPA计算
1023 GPA计算 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 小松终于步入了大学的殿堂,带着兴奋和憧憬,他参加了信息科学 ...
- javaScript中的事件对象event是怎样
事件对象event,每当一个事件被触发的时候,就会随之产恒一个事件对象event,该对象中主要包含了关于该事件的基本属性,事件类型type(click.dbclick等值).目标元素target(我的 ...
- Thread.sleep( ) vs Thread.yield( )
Thread.sleep() The current thread changes state from Running to Waiting/Blocked as shown in the diag ...
- 我从HTML的meta中学到了什么
meta meta中有这样几个常用属性:http-equiv,name,content,包括html5新增的charset. 注意:content属性用来存储meta信息的内容,所有的主流浏览器都支持 ...