杭电1025Constructing Roads In JGShining's Kingdom
地址:http://acm.hdu.edu.cn/showproblem.php?pid=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.
思路:dp题+二分查找。。。依旧没独立做出来,好惨,最近几个dp题全挂==
题意是找最长上升子序列,
懒得写题解了,不是自己想出来的,上一篇写的比较好的题解:http://blog.csdn.net/dangwenliang/article/details/5728363
这题有两种算法n^2和nlogn的,这题用前一个果断会超时。。。
在二分法上卡半天,我也是服了我的智商。。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> #define PI acos((double)-1)
#define E exp(double(1))
using namespace std; #define N 500009
struct point
{
int x,y;
}; struct point city[N];
int a[N]; bool cmp(point &a,point &b)
{
return a.x<b.x;
} int found(int x,int len)
{
int l,r,mid;
l = ;
r = len;
mid = (l+r)/;
while(l <= r)
{
if(a[mid] < x)
{
l = mid+; }
else if(a[mid] > x)
{
r = mid-;
}
mid = (l+r)/;
}
return l;
}
int main (void)
{
int n,k=;
while(scanf("%d",&n) == )
{
int len;
k++;
for(int i = ;i<=n;i++)
{
scanf("%d%d",&city[i].x,&city[i].y);
a[i]= N + ;
}
sort(city+,city+n+,cmp);
a[] = -;
a[] = city[].y;
len = ;
for(int i = ;i<=n;i++)
{
int j = found(city[i].y,len);
a[j] = city[i].y;
if(len < j)
len = j;
}
if(len == )
printf("Case %d:\nMy king, at most %d road can be built.\n\n",k,len);
else printf("Case %d:\nMy king, at most %d roads can be built.\n\n",k,len);
}
return ;
}
杭电1025Constructing Roads In JGShining's Kingdom的更多相关文章
- HDU 1025-Constructing Roads In JGShining's Kingdom(最长不降子序列,线段树优化)
分析: 最长不降子序列,n很大o(n^2)肯定超,想到了小明序列那个题用线段树维护前面的最大值即可 该题也可用二分搜索来做. 注意问题输出时的坑,路复数后加s #include <map> ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 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/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 ...
- 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 ...
- 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(二分查找)
题目链接: Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
随机推荐
- 把查询到结果合并放在一行 JOIN非union
select one.max,one.min,one.low sts,c.high ens,one.time from ( select a.max max,a.min min,b.low low,a ...
- Projects\image_match3图像特征匹配调试记录
D:\文件及下载相关\文档\Visual Studio \Projects\image_match3\image_match #include "opencv2/core/core.hpp& ...
- Linux shell 1-初步认识
1.什么是linux linux是一种操作系统,它可划分为以下四部分 1.linux内核(Linux系统的核心,负责管理系统内存,硬件驱动,文件系统等) 2.GNU工具(一组软件工具,提供一些类UNI ...
- Sort List[leetcode] 由归并排序的递归和循环,到本题的两种解法
归并排序能够有两种思路----top-down 和 bottom-up top-down: 递归实现,将数组分成两半.分别处理.再合并. 伪代码例如以下: split ( A[], l, r) { i ...
- windows查看进程线程的命令pslist
pslist是用命令行查看线程:ProcessExplorer是图形化的查看线程,都在附件中. 1.查看进程 tasklist or pslist -t Name ...
- 【BZOJ4385】[POI2015]Wilcze doły 单调栈+双指针法
[BZOJ4385][POI2015]Wilcze doły Description 给定一个长度为n的序列,你有一次机会选中一段连续的长度不超过d的区间,将里面所有数字全部修改为0.请找到最长的一段 ...
- 《JavaScript高级程序设计》读书笔记1--HTTP头部信息
优秀的书籍常读常新 ----------------------------------------- 在发送XHR请求的同时,还会发送如下头部信息: --Accept: 浏览器能够处理的内容类型 - ...
- CoordinatorLayout Behaviors使用说明[翻译]
翻译与:Intercepting everything with CoordinatorLayout Behaviors 使用过Android Design Support Library的小伙伴应该 ...
- delphi -----(去掉窗口最大化,最小化、关闭),主窗口,和子窗口之间的设置
一.去掉窗口最大化,最小化.关闭 borderIcons:biSystemMenu:false borderStyle:bsSizeable 二.主子窗口 主main: //调用子窗体procedur ...
- [荐][转]为何应该使用 MacOS X(论GUI环境下开发人员对软件的配置与重用)
一周前我和 Tinyfool 闲聊苹果操作系统,都认为对于开发人员来说,苹果操作系统(MacOS)是上佳的选择.Tinyfool 笔头很快,当即就写了一篇长文章,我则笔头很慢,今天才全部码好.他的文章 ...