HDU 3193 Find the hotel
来源:互联网 发布:企业网络信息安全制度 编辑:程序博客网 时间:2024/05/16 15:12
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3193
题目大意:
Flynn又要去旅游了(没钱还旅游还要我们帮忙),想找一个价钱便宜的地方或者离景点近的地方(是不是不打车更加便宜),要是又便宜又离景点近,Flynn会十分开心,
分析题目:
其实就要找p和d最小的组合或者p小(d小)的组合,首先就用了排序,按照先p后d的顺序,第一个肯定满足条件,由于是按照先p后d的顺序,p是递增的,如果pi和第一个p相等,那也满足条件(p小),之后就只用考虑d就可以了,用dis记录前一个d的路径,dis1记录当前的路径的d,再用一个数组记录,如果当前的d小于前一个d,记当前的路径为true,反则为false,如果在后面出现pi相等的情况,就直接考虑pi对应的di和最后一次被记录的dis相比较,如果大于dis为false,小于dis就是true(其实关于这点,我也不是很理解,大家懂的话,希望给我说说,可以给我私信)
下面是代码:
#include <iostream>#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int inf = 99999999;struct node{ int p,d;}e[10010];bool cmp(node a,node b)//先排价钱,在排距离{ if(a.p!=b.p) return a.p<b.p; else return a.d<b.d;}bool f[10010];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d%d",&e[i].p,&e[i].d); sort(e,e+n,cmp); int dis = inf; int dis1 = inf; int cnt=0; for(int i=0;i<n;i++) { if(i>0 && e[i].p!=e[i-1].p) { dis = min(dis1,dis); dis1 = inf; } dis1 = min(dis1,e[i].d); if(dis<e[i].d) f[i]=false; else {f[i]=true;cnt++;} } printf("%d\n",cnt); for(int i=0;i<n;i++) if(f[i]) printf("%d %d\n",e[i].p,e[i].d); } return 0;
}
其实这题是应该用RMQ写的,但是我不会呀。。
好了 现在我要去看那RMQ解法了
阅读全文
0 0
- HDU-3193 Find the hotel
- HDU 3193 Find the hotel
- HDU Find the hotel
- HDU 3193 Find the hotel (RMQ)
- HDU 3193 Find the hotel(RMQ)
- hdu 3193 Find the hotel(RMQ)
- HDU 3193 Find the hotel(RMQ)
- HDU 3193 Find the hotel 【RMQ】
- Find the hotel(HDU-3193) (RMQ)
- Find the hotel(HDU-3193) (RMQ)
- Hdu 3139 Find the hotel
- HDU Find the hotel(RMQ)
- HDU3193-Find the hotel
- HDU 1594 find the max
- hdu find the max(1594)
- hdu 4002 - Find the maximum
- hdu find the nth digit
- [hdu]find the safest road
- SSH的基本使用
- LeetCode-TwoSum
- Android dialog透明
- 对于特征离散化,特征交叉,连续特征离散化非常经典的解释
- 扩展Python模块系列(三)----参数解析与结果封装
- HDU 3193 Find the hotel
- js监听输入框值的即时变化onpropertychange、oninput
- TensorFlow学习笔记(十七)tf.nn.conv2d
- php 7连接mysql数据库
- UE4学习笔记4th:编程和绑定游戏操作
- java中for循环打印星号倒三角以及菱形三角
- Android 原生日期选择
- Watashi's BG (深搜)
- 违章查询怎么这么多李鬼网站?