A -- HDU 4585 Shaolin
2018-06-17 23:42:45来源:未知 阅读 ()
Shaolin
Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
[Submit] [Status] [Discuss]
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
1 #include <iostream> 2 #include <set>//利用set可去重按升序排序 3 #include <map>//利用map将id与武力值映射 4 #include <cmath> 5 using namespace std; 6 int main(){ 7 int n,k,g; 8 set<int>s; 9 map<int,int>m; 10 while(cin>>n){ 11 if(n==0) break; 12 s.clear(); 13 m.clear(); 14 s.insert(1000000000);//将master入集合 15 m[1000000000]=1;//记录master的编号 16 while(n--){ 17 cin>>k>>g;//输入新和尚的编号k与武力值g 18 cout<<k<<" "; 19 set<int>::iterator it1,it2; 20 it1=s.lower_bound(g);//it1为第一个武力值大于等于g的和尚的地址 21 if(it1==s.begin()) cout<<m[*it1]<<endl; 22 else { 23 it2=it1--; 24 if(abs(*it1-g)>abs(*it2-g)) cout<<m[*it2]<<endl; 25 else cout<<m[*it1]<<endl; 26 } 27 s.insert(g);//当前新和尚比武完成,将他的武力值入集合,供以后使用 28 m[g]=k;//记录该武力值g所对应的编号k 29 } 30 } 31 return 0; 32 }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash