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 ...
随机推荐
- 基于jQuery的input输入框下拉提示层(自动邮箱后缀名)
基于jQuery的input输入框下拉提示层,方便用户输入邮箱时的提示信息,需要的朋友可以参考下 效果图 // JavaScript Document (function($){ $.fn ...
- [leetcode]Combine Two Tables
leetcode竟然有sql的题了..两道简单的应该会做 这个题主要就是一个left join... # Write your MySQL query statement below SELECT P ...
- Ranorex入门指南
Ranorex入门指南 http://automationqa.com/forum.php?mod=viewthread&tid=2766&fromuid=29
- Java数组,去掉重复值、增加、删除数组元素
import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; p ...
- java之源码路径及api
jav源码地址:D:\Program Files\jdk1.7\src.zip class类地址:D:\Program Files\jdk1.7\jre\lib\rt.jar 在线api底地址:htt ...
- 十六、【适合中小企业的.Net轻量级开源框架】EnterpriseFrameWork框架核心类库之单点登录SSO
回<[开源]EnterpriseFrameWork框架系列文章索引> EFW框架源代码下载:http://pan.baidu.com/s/1qWJjo3U 单点登录(Single Sign ...
- [原]零基础学习在Android进行SDL开发系列文章
[原]零基础学习SDL开发之移植SDL2.0到Android [原]零基础学习SDL开发之在Android使用SDL2.0显示BMP图 [原]零基础学习SDL开发之在Android使用SDL2.0显示 ...
- windbg入门
1.下载安装windbg Windows 10 调试工具 (WinDbg) 如果你仅需要 Windows 10 调试工具,而不需要 WDK 10 或 Visual Studio 2015,你可以将调试 ...
- 树莓派 LED+蜂鸣+声音传感器+红外模块组合打造声控/红外控制LED
昨天搞了控制LED,玩了第一个,剩下的就感觉很简单了,这里记录一下 先来几张照片 玩了蜂蜜模块才发现规律,一般这种模块,都会有三个针脚,VCC(3.3V或5V供电输出针脚).GNC(对应GPIO针脚的 ...
- 从头学Qt Quick(2)-- QML语法从一个简单的例子说起
在上一篇文章中,我们对QtQuick做了简单的介绍,体验了使用QML语言构建一个UI的便捷.这里我们简要介绍一下QML的语法. QML将界面分成一些更小的元素,这些元素可以组成一个组件,QML语言描述 ...