Find the hotel HDU - 3193(RMQ)
题意:
有n个旅馆,从这n个旅馆中找出若干个旅馆,使得这若干个旅馆满足这样的条件:不能从其它和剩下的旅馆中找到一个价格和距离都小于这个旅馆的旅馆。。。
解析:
按price 排序,若price相同, 则按距离排序
然后遍历每一个旅馆,在处理当前 旅馆时,二分在price小于当前旅馆price的旅馆中 找到最后一个price小于当前旅馆price的旅馆(因为可能price相同)
然后rmq求距离最小值就可
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int d[maxn][];
int n;
struct node
{
int price, dis;
}Node[maxn]; bool cmp(node a, node b)
{
if(a.price == b.price) return a.dis < b.dis;
return a.price < b.price;
} int rmq(int l, int r)
{
int k = ;
while((<<(k+)) <= r-l+) k++;
return min(d[l][k], d[r-(<<k)+][k]); } int main()
{
while(~scanf("%d", &n))
{
vector<node> v;
rep(i, , n)
{
scanf("%d%d", &Node[i].price, &Node[i].dis);
}
sort(Node, Node+n, cmp);
rap(i, , n)
d[i][] = Node[i].dis;
for(int j=; (<<j) <= n; j++)
for(int i=; i+(<<j)- < n; i++)
d[i][j] = min(d[i][j-], d[i+(<<(j-))][j-]); v.push_back(Node[]);
for(int i=; i<n; i++)
{
int x = , y = i; //lower_bound实现 返回第一次出现当前price的位置
while(x < y)
{
int mid = x + (y-x) / ;
if(Node[mid].price >= Node[i].price) y = mid;
else x = mid + ;
}
if(x == )// 如果当前price就是最小的
{
v.push_back(Node[i]);
continue;
}
int h = rmq(, x-); //查询0到x-1中是否存在一个dis小于当前dis
if(h >= Node[i].dis) //如果不存在
v.push_back(Node[i]);
}
printf("%d\n", v.size());
for(int i=; i<v.size(); i++)
printf("%d %d\n", v[i].price, v[i].dis); } return ;
}
Find the hotel HDU - 3193(RMQ)的更多相关文章
- Find the hotel HDU - 3193 (ST表RMQ)
Summer again! Flynn is ready for another tour around. Since the tour would take three or more days, ...
- HDU - 6305 RMQ Similar Sequence(笛卡尔树)
http://acm.hdu.edu.cn/showproblem.php?pid=6305 题目 对于A,B两个序列,任意的l,r,如果RMQ(A,l,r)=RMQ(B,l,r),B序列里的数为[0 ...
- hdu 6305 RMQ Similar Sequence——概率方面的思路+笛卡尔树
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6305 看题解,得知: 0~1内随机取实数,取到两个相同的数的概率是0,所以认为 b 序列是一个排列. 两个 ...
- hdu 1806 rmq
找到一个区间内出现最多的数的次数 10 3 //10个数字三次询问 -1 -1 1 1 1 1 3 10 10 10 2 3 1 10 5 10 0 143 #include<cstdio> ...
- HDU 6305.RMQ Similar Sequence-笛卡尔树+数学期望 (2018 Multi-University Training Contest 1 1008)
6305.RMQ Similar Sequence 这个题的意思就是对于A,B两个序列,任意的l,r,如果RMQ(A,l,r)=RMQ(B,l,r),B序列里的数为[0,1]的实数,B的重量为B的所有 ...
- HDU 5696 RMQ+滑窗
区间的价值 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 3183 rmq+鸽巢原理
题目大意: 给你一个数字字符串序列,给你要求删掉的数字个数m,删掉m个数使的剩下的数字字符串的之最小.并输出这个数字: 基本思路; 这题解法有很多,贪心,rmq都可以,这里选择rmq,因为很久没有写r ...
- 2018 Multi-University Training Contest - Team 1 题解
Solved A HDU 6298 Maximum Multiple Solved B HDU 6299 Balanced Sequence Solved C HDU 6300 Triangle Pa ...
- HDU 5726 GCD (RMQ + 二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...
随机推荐
- Kettle数据源连接配置
说明: 通过(图3.1)我们可以看到创建数据源时需要配置相应的参数: Connection Name(必填):配置数据源使用名称,如:Rot_Source Host Name(必填):数据库主机IP地 ...
- Spring Cloud Learning(一): 服务注册
官网https://projects.spring.io/spring-cloud/,spring cloud官网各组件版本为: Component Edgware.SR4 Finchley.SR1 ...
- Phaser3 场景Scene之间的传值 -- HTML JAVASCRIPT 网页游戏开发
PHASERJS3 一.首先当然得有至少有二个场景sceneA.js,sceneB.js 二.从场景A传值到场景B二种方法 1)通过事件this.events.emit('event key',{ ...
- Siki_Unity_3-8_Lua编程(未完)
Unity 3-8 Lua编程 任务1&2&3:前言 课程内容: Lua从入门到掌握 为之后的xLua和其他热更新方案打下基础 任务4:Lua简介 Lua是轻量小巧的脚本语言--无需编 ...
- HBASE理论篇
1.Hbase是什么 HBase是一种构建在HDFS之上的分布式.面向列的存储系统.在需要实时读写.随机访问超大规模数据集时,可以使用HBase. 尽管已经有许多数据存储和访问的策略和实现方法,但事实 ...
- Oracle集合
--union 并集 select * from emp where ename like '%A%' union select * from emp where ename like '%M%'; ...
- 搭建docker 私有镜像仓库
前期准备 服务器:centos 7.3 docker-ce: 18.06.1-ce docker-compose: 1.22.0 docker 安装 首先,更新系统 yum update yum up ...
- C#匿名参数(转载too)
匿名方法是在初始化委托时内联声明的方法. 例如下面这两个例子: 不使用匿名方法的委托: using System; using System.Collections.Generic; using Sy ...
- New begin
Purpose 今天更换了id,希望重新沉淀. 晚上看到国外一个博客,落款有个中文: 敬惜字纸. 共勉.
- 雅虎工程师提供的CSS初始化示例代码
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...