Summer again! Flynn is ready for another tour around. Since the tour would take three or more days, it is important to find a hotel that meets for a reasonable price and gets as near as possible!

But there are so many of them! Flynn gets tired to look for any. It’s your time now! Given the <p i, d i> for a hotel h i, where p i stands for the price and d i is the distance from the destination of this tour, you are going to find those hotels, that either with a lower price or lower distance. Consider hotel h 1, if there is a hotel h i, with both lower price and lower distance, we would discard h1. To be more specific, you are going to find those hotels, where no other has both lower price and distance than it. And the comparison is strict.

Input

There are some cases. Process to the end of file.

Each case begin with N (1 <= N <= 10000), the number of the hotel.

The next N line gives the (p i, d i) for the i-th hotel.

The number will be non-negative and less than 10000.

Output

First, output the number of the hotel you find, and from the next line, print them like the input( two numbers in one line). You should order them ascending first by price and break the same price by distance.

Sample Input

3

15 10

10 15

8 9

Sample Output

1

8 9

题意:

给你n个酒店的信息,包括价格和距离,问有哪些酒店满足条件?

条件是:不存在任意一个其他的酒店价格和距离都比该酒店低。

思路:

我们先以价格为first标准对 酒店 进行排序,然后建立对去距离的ST表,

到第i酒店时询问比当前第i个价格低的酒店中最小的距离是多少?如果最小的距离小于第i个酒店的距离,那么该酒店就合法。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 10010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
pii a[maxn];
int st1[maxn][25];//st表 void init(int n)
{
for (int i = 0; i < n; i++) {
st1[i][0] = a[i].se;
}
for (int i = 1; (1 << i) <= n; i++) {
for (int j = 0; j + (1 << i) - 1 < n; j++) {
st1[j][i] = min(st1[j][i - 1], st1[j + (1 << (i - 1))][i - 1]);
}
}
} int query1(int l, int r)
{
int k = (int)(log((double)(r - l + 1)) / log(2.0));
return min(st1[l][k], st1[r - (1 << k) + 1][k]);
}
bool cmp(pii id1, pii id2)
{
if (id1.fi != id2.fi) {
return id1.fi < id2.fi;
} else {
return id1.se < id2.se;
}
}
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout); gbtb;
int n;
while (cin >> n) {
repd(i, 0, n - 1) {
cin >> a[i].fi >> a[i].se; }
sort(a, a + n, cmp);
init(n);
std::vector<int> idset;
int id = 1;
rep(i, 0, n) {
if (a[i].fi != a[id].fi) {
id = i;
}
int num = query1(0, id - 1);
if (num >= a[i].se) {
idset.push_back(i);
}
}
cout << sz(idset) << endl;
for (auto x : idset) {
cout << a[x].fi << " " << a[x].se << endl;
} }
return 0;
} inline void getInt(int *p)
{
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
} else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Find the hotel HDU - 3193 (ST表RMQ)的更多相关文章

  1. ST表 || RMQ问题 || BZOJ 1699: [Usaco2007 Jan]Balanced Lineup排队 || Luogu P2880 [USACO07JAN]平衡的阵容Balanced Lineup

    题面:P2880 [USACO07JAN]平衡的阵容Balanced Lineup 题解: ST表板子 代码: #include<cstdio> #include<cstring&g ...

  2. Find the hotel HDU - 3193(RMQ)

    题意: 有n个旅馆,从这n个旅馆中找出若干个旅馆,使得这若干个旅馆满足这样的条件:不能从其它和剩下的旅馆中找到一个价格和距离都小于这个旅馆的旅馆... 解析: 按price 排序,若price相同, ...

  3. hdu2888 二维ST表(RMQ)

    二维RMQ其实和一维差不太多,但是dp时要用四维 /* 二维rmq */ #include<iostream> #include<cstring> #include<cs ...

  4. POJ 3368 Frequent values 【ST表RMQ 维护区间频率最大值】

    传送门:http://poj.org/problem?id=3368 Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  5. cf689d ST表RMQ+二分

    类似hdu5289,但是二分更复杂.本题枚举左端点,右端点是一个区间,需要二分找到区间的左端点和右端点(自己手动模拟一次),然后区间长度就是结果增加的次数 另外结果开long long 保存 /** ...

  6. Balanced Lineup 倍增思想到ST表RMQ

      Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 36864   Accepted: 172 ...

  7. CSU-2221 假装是区间众数(ST表模版题)

    题目链接 题目 Description 给定一个非递减数列Ai,你只需要支持一个操作:求一段区间内出现最多的数字的出现次数. Input 第一行两个整数N,Q 接下来一行有N个整数,表示这个序列. 接 ...

  8. HDU 4123 Bob’s Race 树的直径+ST表

    Bob’s Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=41 ...

  9. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

随机推荐

  1. Win7、win8、win10下实现精准截获Explorer拷贝行为

    介绍了windows下对Explorer的拷贝动作的精确截获,这个在企业数据安全dlp产品系列中减少审计的噪音很有效,方便运营人员做针对性的审计. 在企业数据安全中我通常需要监测用户的拷贝行为,特别像 ...

  2. LeetCode 5——最长回文子串

    1. 题目 2. 解答 我们定义状态 state[i][j] 表示子串 s[i, j] 是否为回文子串,如果 s[i, j] 为回文子串,并且有 s[i-1] == s[j+1],那么 s[i-1, ...

  3. 请介绍下 adb、ddms、aapt 的作用

    adb 是 Android Debug Bridge ,Android 调试桥的意思 ddms 是 Dalvik Debug Monitor Service,dalvik 调试监视服务. aapt 即 ...

  4. SQL2008附加数据库报错

    sql server 2008如何导入mdf,ldf文件 网上找了很多解决sql server导入其他电脑拷过来的mdf文件,多数是不全,遇到的解决方法不一样等问题,下边是找到的解决问题的最全面方法! ...

  5. [VBA]指定列求和

    ##指定列求和 需求: 求和:列为“销售金额”的数值 Sub 求和()Dim i As Integer, j As IntegerFor i = 3 To 56For j = 15 To 81 Ste ...

  6. Windows下C/C++内存泄露检测机制

    1.概述 在Windows下微软给我们提供了一个十分强大的C/C++运行时库,这个运行时库中包含了很多有用的功能.而众多强大功能之一就是内存泄露的检测. C/C++提供了强大的内存管理功能,不过随之而 ...

  7. 无界面上(linux)生成测试报告(3)

    无界面上(linux)生成测试报告 1.待jmx文件运行完成后,键入命令进入到jtl文件下: #cd testresult#bin目录下使用此命令,进入到jtl文件下 #jmeter -g pushG ...

  8. Java编写时钟 Applet 程序

    简单分析: package clockApplet; import java.applet.Applet; import java.awt.Color; import java.awt.Graphic ...

  9. 437路径总和III

    题目: 给定一个二叉树,它的每个结点都存放着一个整数值.找出路径和等于给定数值的路径总数.路径不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点).来源: ht ...

  10. 学习Go语言(一)环境安装及HelloWorld

    自己开发的时候,一般用Java和C#居多,偶尔也用Python做点东东. 想体验一下比较“现代”语言,思来想去就来体验一下Go语言. 闲话少叙,言归正传,首先就是环境安装,这个轻车熟路: (1)到官网 ...