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 ...
随机推荐
- JQuery--extend的使用
$.extend({a,b,c},{a,bd}); 里面的对象属性如果 存在就替换,如果不存在就添加 var loadData = function (order) { var obj = getPa ...
- 惊!VUE居然数据不能驱动视图?$set详细教程
众所周知.VUE最大的优点就是数据驱动视图.当数据发生改变时,会监听到变化,后渲染到页面上.那么为什么当我们在修改data中声明的数组或对象时.VUE并没有监听到变化呢?这个我也不知道.我们可以后续再 ...
- WPF 单个模块换肤
xmal: <Window x:Class="wpfSkin.MainWindow" xmlns="http://schemas.microsoft.com/win ...
- JAVA读取文件操作时路径的斜杠问题
java中的路径一般用"/"windows中的路径用"\"linux,unix中的路径一般用"/"其中java中"/"等 ...
- java.lang.IllegalStateException: 1 matchers expected, 5 recorded.
这是一个很神奇的错误. 常规的出错是因为在mock方法里,其中某一个或者几个参数使用了EasyMock.anyxx(),而其他的使用了具体的值. java.lang.IllegalStateExcep ...
- MySQL数据库起步 关于数据库的基本操作(更新中...)
mysql的基本操作 连接指定的服务器(需要服务器开启3306端口) mysql -h ip地址 -P 端口号 -u 账号 -p 密码 删除游客模式 mysql -h ip地址 -P 端口号 -u 账 ...
- Docker Tomcat部署
1.下载tomcat镜像 docker pull tomcat 2.上传项目 /etc/tomcat/webapps/ 3.启动tomcat容器 docker run -d --name tomcat ...
- vue 使用 element ui动态添加表单
html部分 <div class="hello"> <el-form :model="dynamicValidateForm" ref=&q ...
- Win7x64易语言调试进程无法退出
这是个历史问题,几乎所有的Win7x64机器上都会碰到这个问题 解决方法: 启动黑月重新编译器
- 洛谷P1650 赛马[2017年5月计划 清北学堂51精英班Day1]
P1650 赛马 题目描述 我国历史上有个著名的故事: 那是在2300年以前.齐国的大将军田忌喜欢赛马.他经常和齐王赛马.他和齐王都有三匹马:常规马,上级马,超级马.一共赛三局,每局的胜者可以从负者这 ...