A -- HDU 4585 Shaolin
Shaolin
Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
Description
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
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
Sample Input
3
2 1
3 3
4 2
0
Sample Output
2 1
3 2
4 2
Source
#include <iostream>
#include <set>//利用set可去重按升序排序
#include <map>//利用map将id与武力值映射
#include <cmath>
using namespace std;
int main(){
int n,k,g;
set<int>s;
map<int,int>m;
while(cin>>n){
if(n==) break;
s.clear();
m.clear();
s.insert();//将master入集合
m[]=;//记录master的编号
while(n--){
cin>>k>>g;//输入新和尚的编号k与武力值g
cout<<k<<" ";
set<int>::iterator it1,it2;
it1=s.lower_bound(g);//it1为第一个武力值大于等于g的和尚的地址
if(it1==s.begin()) cout<<m[*it1]<<endl;
else {
it2=it1--;
if(abs(*it1-g)>abs(*it2-g)) cout<<m[*it2]<<endl;
else cout<<m[*it1]<<endl;
}
s.insert(g);//当前新和尚比武完成,将他的武力值入集合,供以后使用
m[g]=k;//记录该武力值g所对应的编号k
}
}
return ;
}
A -- HDU 4585 Shaolin的更多相关文章
- HDU 4585 Shaolin(Treap找前驱和后继)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Su ...
- HDU 4585 Shaolin(STL map)
Shaolin Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit cid= ...
- [HDU 4585] Shaolin (map应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585 题目大意:不停的插入数字,问你跟他相距近的ID号.如果有两个距离相近的话选择小的那个. 用map ...
- hdu 4585 Shaolin treap
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem ...
- hdu 4585 Shaolin(STL map)
Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...
- HDU 4585 Shaolin (STL)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- HDU 4585 Shaolin(水题,STL)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- HDU 4585 Shaolin (STL map)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- hdu 4585 Shaolin
原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46093 #include<algorithm> #in ...
随机推荐
- MT写的对URL操作的两个方法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- StringEx
static class StringEx { public static string MD5(this String str) { byte[] bytes = new MD5CryptoServ ...
- linux ss 网络状态工具
ss是Socket Statistics的缩写 查看网络状态,经常用的命令: watch ss -lnt ss命令用于显示socket状态. 他可以显示PACKET sockets, TCP soc ...
- assets中放入中文文件名导致Android Studio编译错误
一个android项目突然出现编译错误,如下: :app:processDebugResources FAILED FAILURE: Build failed with an exception. * ...
- 三种ViewController跳转的异同
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag comple ...
- Unity Remote 4安卓机使用指南
必须U3D版本为4.5以上,可以在Public目录下载.想实时调试IOS版本必须是MAC系统! 优点:可以在不编译的情况下实时的去调试真实Android设备的各种情况,包括使用触摸功能(Remote接 ...
- CocoStudio教程三:认识并利用CocoStudio的果实 运行2.2.1版本
原文:CocoStudio教程三:认识并利用CocoStudio的果实 原文用的老版,用2.21搞起来好像有些问题,然后自己摸索了下,有的都是乱找的方法,只求能运行... 1,原文的CCJsonRea ...
- Android working with Volley
Volley是google官方推出的一个开源网络访问库,在项目中直接使用它,而不需要写一大堆的重复的代码; 项目主页: https://android.googlesource.com/platfor ...
- windows7 中开启无线热点
我用的是移动的 CMCC-EDU 上网,但是这个只能在一个设备上登陆,那么问题就来了,当我电脑需要用网,手机也想要用网(不用 2/3/4G)该怎么办? 电脑操作系统:windows7 接下来是开启 w ...
- Android开发环境搭建相关文章列表(转载)
Android开发虽然有所了解,但是一直没有搭建开发环境去学习,Android的更新速度比较快了,Android1.0是2008年发布的,截止到目前为止Android已经更新Android5.0.1, ...