ACM.hdu1025
to get the ans of how many roads at most that can be built between two line without intersection of roads,we need sort the input sequence at ont edge and then deal with anther line with LIS
way,meanwhile, not forget using the nlogn way.
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
struct LINE
{
int from,to;
friend bool operator<(LINE A,LINE B)
{
return A.from<B.from;
}
};
LINE node[N];
int y[N];
int c[N];
int MID(int a[],int value,int size)
{
int l=,r=size;
int mid=(l+r)/;
while(l<r)//1 3 5 7 9 3
{
if(a[mid]<value&&value<=a[mid+])return mid+;
else if(value<=a[mid])r=mid;
else l=mid+;
mid=(l+r)/;
}
}
int LIS(int len)
{
int size=;
int zhong=;
c[]=y[];
for(int i=;i<=len;i++)//7 6 4 9 11 14 17 3 15 20 4 5 6 7 8
{//3 9 11 15 17 20
if(y[i]<=c[])c[]=y[i];
else if(y[i]>c[size])
c[++size]=y[i];
else
{
zhong=MID(c,y[i],size);
c[zhong]=y[i];
}
}
return size;
}
int main()
{
int n;
int cnt=;
while(cin>>n)
{
for(int i=;i<n;i++)
scanf("%d %d",&node[i].from,&node[i].to);
sort(node,node+n);//sort one side by ascending direction
for(int i=;i<n;i++)
y[i+]=node[i].to;
int ans=LIS(n);
cout<<"Case "<<cnt<<':'<<endl;
cout<<"My king, at most "<<ans;
if(ans>)cout<<" roads can be built."<<endl;
else cout<<" road can be built."<<endl;
cnt++;
cout<<endl;
}
return ;
}
It has used the longest increasing subsequence algorithm way,and to get it solved after you have learned it.
input : with a n,represent n pairs of integers followed.And n pairs of intergers followed
output:
Cast i:
My king, at most n road(s) can be built
A sample below:
11
2 5
3 6
4 2
5 1
6 9
7 11
8 7
9 12
10 8
11 4
12 10
Case 1:
My king, at most 6 road can be built.
ACM.hdu1025的更多相关文章
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- acm结束了
最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!
- 关于ACM的总结
看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...
- 第一届山东省ACM——Phone Number(java)
Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
- ACM之鸡血篇
一匹黑马的诞生 故事还要从南京现场赛讲起,话说这次现场赛,各路ACM英雄豪杰齐聚南京,为争取亚洲总舵南京分舵舵主之职位,都使出了看 家本领,其中有最有实力的有京城两大帮清华帮,北大帮,南郡三大派上交派 ...
随机推荐
- Linux内核设计笔记7——中断
中断与中断处理 何为中断? 一种由设备发向处理器的电信号 中断不与处理器时钟同步,随时可以发生,内核随时可能因为中断到来而被打断. 每一个中断都有唯一一个数字标志,称之为中断线(IRQ) 异常是由软件 ...
- NSValue的valueWithBytes:objCType:方法
+ (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type; NSValue的valueWithBytes: ...
- Lecture Sleep(尺取+前缀和)
Description 你的朋友Mishka和你参加一个微积分讲座.讲座持续n分钟.讲师在第i分钟讲述ai个定理. 米什卡真的对微积分很感兴趣,尽管在演讲的所有时间都很难保持清醒.给你一个米什卡行 ...
- 20172330 2017-2018-1 《Java程序设计》第九周学习总结
20172330 2017-2018-1 <程序设计与数据结构>第九周学习总结 教材学习内容总结 本周的学习包括两章内容,分别为异常和递归. 异常 错误和异常都是对象,代表非正常情况或者无 ...
- Java微笔记(1)
一,Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索 1. 排序 语法: Arrays.sort(数 ...
- Debian实验机 常用命令
1.开启中文输入法 fcitx 2. 开启无线连接 wicd 3. 远程连接 ssh root@XXX.XXX.XXX.XXX 4. 启动Ulipad ~/ulipad-master# python ...
- PAT 甲级 1048 Find Coins
https://pintia.cn/problem-sets/994805342720868352/problems/994805432256675840 Eva loves to collect c ...
- 第三部分shell编程3(shell脚本编写1)
做监控和备份最多 1. shell脚本是什么它是一种脚本语言,并非编程语言可以使用一些逻辑判断.循环等语法可以自定义子函数是系统命令的集合shell脚本可以实现自动化运维,大大增加我们的工作效率 第一 ...
- java 基础--继承--007
1,子类只能继承父类所有非私有成员 2,子类不能继承父类的构造方法,但可以通过super去访问父类构造方法 3,子类成员变量和父类成员变量名称不一样,如果一样类似于重写,按子类处理,如果一样,就近原则 ...
- 【转】how can i build fast
http://blog.csdn.net/pcliuguangtao/article/details/5830860