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 ...
随机推荐
- Hdu 1402 (FFT)
题目链接 A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- WPF 实现简单的跑马灯
本文用WPF的动画实现一个简单的跑马灯 xmal: <Window x:Class="wpfstatusBar.MainWindow" xmlns="http:// ...
- CentOS7系统ifconfig无法使用的解决方法
在使用RAKsmart美国服务器的时候,如果安装的CentOS7操作系统的话,可能会经常用到“ifconfig”命令.ifconfig命令大多是用于CentOS 6版本下面,主要用于查看网卡配置信息. ...
- HDU5583 Kingdom of Black and White
Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- NOIP模拟 9.09
AK300分 果实计数 (count.pas/.c/.cpp) 时间限制:1s,空间限制32MB 题目描述: 淘淘家有棵奇怪的苹果树,这棵树共有n+1层,标号为0~n.这棵树第0层只有一个节点,为根节 ...
- Leetcode78. Subsets子集
给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3] 输出: [ [3], [1], [2 ...
- itextsharp 1.0
1 效果图 2.代码 引用组件: using iTextSharp.text;using iTextSharp.text.pdf;using System;using System.Data;usin ...
- Handling Missing Values
1) A Simple Option: Drop Columns with Missing Values 如果这些列具有有用信息(在未丢失的位置),则在删除列时,模型将失去对此信息的访问权限. 此外, ...
- QT_string转char*
char* convertQString2char(const QString &str) { QByteArray ba = str.toUtf8(); char * pathChar = ...
- Vim 中自定义注释快捷键
写程序的时候写过的代码不忍心立马删掉,所以注释很多,所以找了下注释的快捷健. 打开 /etc/vim/vimrc文件,添加如下两行代码即可. /* 注释该行 */ map = I/* ^[A */j ...