题意:
给出从N-1个点的id(2~N)和权值并保证每个点的id个权值不一样,每输入一个点,输出先前给出的点中权值最接近的点的id,若有多个点满足条件输出id较小的那个。

起初的第一个点权值为 1e9。

思路:
题意简单来说无非就是做一个在线数据的插入和查询,数据的数量为1e5次,数据的最大值为5e6。

根据题意很容易想到时AVL树,stl实现即可。也可以用离散化线段树完成,但十分复杂,在这就不给出了。

代码:

(STL)

#include <bits/stdc++.h>using namespace std;
const int MAXN=1000000000;
typedef struct Node{int x;int y;Node(int xx=0,int yy=0){x=xx;y=yy;}bool operator < (const Node &a)const{if(a.y==y)return a.x<x;return a.y>y;}
}Node;
int main()
{set <Node> ans;int n,fans;while(~scanf("%d",&n)&&n){ans.clear();ans.insert(Node(1,MAXN));Node t;scanf("%d%d",&t.x,&t.y);cout<<t.x<<' '<<1<<endl;ans.insert(t);for(int i=1;i<n;i++){scanf("%d%d",&t.x,&t.y);set <Node>::iterator it=ans.upper_bound(t);if(it==(ans.begin()++)){//cout<<it->x<<' '<<it->y<<endl;fans=it->x;}else{Node ans1=*it;Node ans2=*(--it);//cout<<"ans1 :"<<ans1.x<<' '<<ans1.y<<endl;//cout<<"ans2 :"<<ans2.x<<' '<<ans2.y<<endl;if(abs(ans1.y-t.y)<abs(ans2.y-t.y)){fans=ans1.x;}else{fans=ans2.x;}}cout<<t.x<<' '<<fans<<endl;ans.insert(t);}}
}
Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every year, trying to be a monk there. The master of Shaolin evaluates a young man mainly by his talent on understanding the Buddism scripture, but fighting skill is also taken into account. 
When a young man passes all the tests and is declared a new monk of Shaolin, there will be a fight , as a part of the welcome party. Every monk has an unique id and a unique fighting grade, which are all integers. The new monk must fight with a old monk whose fighting grade is closest to his fighting grade. If there are two old monks satisfying that condition, the new monk will take the one whose fighting grade is less than his. 
The master is the first monk in Shaolin, his id is 1,and his fighting grade is 1,000,000,000.He just lost the fighting records. But he still remembers who joined Shaolin earlier, who joined later. Please recover the fighting records for him. 

Input

There are several test cases. 
In each test case: 
The first line is a integer n (0 <n <=100,000),meaning the number of monks who joined Shaolin after the master did.(The master is not included).Then n lines follow. Each line has two integer k and g, meaning a monk's id and his fighting grade.( 0<= k ,g<=5,000,000) 
The monks are listed by ascending order of jointing time.In other words, monks who joined Shaolin earlier come first. 
The input ends with n = 0. 

Output

A fight can be described as two ids of the monks who make that fight. For each test case, output all fights by the ascending order of happening time. Each fight in a line. For each fight, print the new monk's id first ,then the old monk's id.

Sample Input

3
2 1
3 3
4 2
0

Sample Output

2 1
3 2
4 2

HDU 4585 Shaolin (STL)相关推荐

  1. hdu 4585 Shaolin set

    lower_bound 返回第一个不小于  key值的 迭代器. #include<iostream> #include<set> #include<map> #i ...

  2. Shaolin(map+iterator) HDU - 4585

    Shaolin(map+iterator) HDU - 4585 少林寺以武僧而闻名.每年都有很多年轻人去少林寺当和尚.少林的主人评估一个年轻人主要通过他的人才了解佛教经文,但武功也考虑在内. 当一个 ...

  3. Shaolin HDU - 4585(map模板题)

    题意: 少林寺有n+1个和尚,他们都有一个独有的编号和战斗力值,当一个年轻人通过所有考试并被宣布为少林的新僧人时,将会有一场战斗,作为欢迎的一部分.新和尚必须与一位战斗等级最接近他的战斗等级的老和尚战 ...

  4. mono桌面应用移到android,从原生APK反编译,拿到界面,用于mono for android

    从原生APK反编译,拿到界面,用于mono for android 1.用apktool反编译apk,得到xxx.apk.de 2.从xxx.apk.de\res\layout 3.复制所有xml到M ...

  5. hdu 4268 Alice and Bob(STL版)

    http://acm.hdu.edu.cn/showproblem.php?pid=4268 这是今天网络赛的水题,下午短路了,没想到怎么做.队友hq是用treap做的,不过赛后我才想懂怎么做,回到宿 ...

  6. hdu 5265 pog loves szh II STL

    pog loves szh II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  7. hdu 4409 Family Name List LCA +stl

    http://acm.hdu.edu.cn/showproblem.php?pid=4409 赛后才过只能说悲剧了,知道思路,stl不熟悉,所以导致写的很慢....占据了很多时间,手速+代码准确度.. ...

  8. 素数环(dfsamp;amp;STL做法)HDU - 1016

    HDU - 1016  cxsys训练第一周&第二周 A ring is compose of n circles as shown in diagram. Put natural numbe ...

  9. STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:

    HDU - 1716 Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡片上的数字(0&l ...

  10. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

    题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...

最新文章

  1. windows测试模式打开关闭
  2. 【智力问题】25匹马赛跑,每次只能跑5匹马,最快能赛几次找出跑得最快的3匹马?赛跑不能计时,并假设每匹马的速度是恒定不变的。...
  3. c++ 纯虚函数和抽象类那些事(二)实现抽象类
  4. 通过OWA修改密码,提示输入的密码不符合最低安全要求
  5. 开源开放 | Beyond 预训练语言模型,NLP还需要什么样的知识?
  6. python安装百度aip_Python3.6安装aip
  7. Java文件类String [] list(FilenameFilter fnf)方法,带示例
  8. 我整理的一个经典分页程序(JSP的)
  9. PyTorch: torch.optim 的6种优化器及优化算法介绍
  10. Protel99SE推荐使用英文版
  11. 黑客社会工程学攻击特别危险,你知道多少?
  12. 2048小游戏(Java)源码解析及源代码打包
  13. Android实现省市区三级联动效果
  14. showModalDialog()、showModelessDialog()方法使用详解
  15. C#类库推荐 拼多多.Net SDK,开源免费!
  16. 南京大学计算机学院英才计划,南京大学以“英才计划”为切入点 向前衔接高中...
  17. NVENC/NVDEC 10bits 编程
  18. exp与expdp区别
  19. 《JSP程序设计》手机销售网后台设计
  20. 二手车电商风波:改革路上,请给予一定的容错空间!

热门文章

  1. String slices
  2. 随机矩阵stochastic matrix和双随机矩阵 doubly stochastic matrix 和bistochastic matrix
  3. c语言编译bss和data,bss段和data段的区别
  4. 2009年的MACBOOK苹果电脑重装MAC OS 10.8.5系统
  5. Beta 反(tu)思(cao) 获小黄衫感言
  6. Safari 神器,手机平板都能用,我们找到了 14 个超实用浏览器插件
  7. P2627 [USACO11OPEN]Mowing the Lawn G (单调队列优化dp)
  8. java 实现扑克牌洗牌功能
  9. Qt 简单截图工具(一) 高仿QQ截屏 滑动截屏
  10. 计算机画图保存的图片怎么找到,想知道电脑截图保存在哪儿找