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 ...
随机推荐
- goland快捷键使用
查找替换: 格式化代码块:ctrl+alt+L将选中的行自动对齐:ctrl+alt+I优化没必要的imports:ctrl+alt+O展开代码块:ctrl+“+”展开文件中所有代码块:ctrl+shi ...
- Kotlin 委托(2)变量委托是什么、自定义变量委托
1.委托是什么? 1.1 官网示例 在每个变量委托的实现的背后,Kotlin 编译器都会生成辅助对象并委托给它. 假设委托如下, class C { var prop: Type by MyDeleg ...
- sql 分页rownumber方式
alter procedure [dbo].[proc_getpaging] ( ), --表名(可以为多表) ) = '*', --字段名(全部字段为*) ), --排序字段(支持多字段不用加ord ...
- ios h5 出现的问题
这几天在测试的时候,忽然发现手机ios 页面中的input 样式出现问题,安卓就没事. 实际应该是第一张图,在ios中出现的结果为第二张图 出现这个原因,主要是ios系统自带的设置,解决方法为 ...
- PHP--时间格式处理
Ymd格式转Y-m-d或转成时间戳将Ymd格式如19930811转成1993-08-11格式 date('Y-m-d',strtotime('19930811') 将Ymd格式如19930811转成时 ...
- 在vscode中使用字体Cascadia Code
下载字体 下载地址:github:https://github.com/microsoft/cascadia-code/releases 安装字体(windows10) 设置 > 个性化 > ...
- hibernate分页功能
设置开始位置无效 设置终止位置是可以的 设置完之后,并没有分页 问题解决 https://blog.csdn.net/qq_39859824/article/details/77902488 http ...
- JAVA邀请码生成器
code import java.util.Random; /** * 邀请码生成器,算法原理:<br/> * 1) 获取id: 1127738 <br/> * 2) 使用自定 ...
- 2017-09-23-ArchData
layout: post title: ArchData category: Technical tags: [分布式,区块链,AI,大数据] ArchData 技术峰会 神经网络和函数式编程 杨博: ...
- chmod 777 修改权限之后,文件夹颜色变绿:解决方案
修改前: 方法一: ls --color=none #不显示颜色 方法一修改后: 方法二:修改配色 ①安装git +++可用在windows下载之后用ftp传上去:http://pan.baidu.c ...