hdu 4585 map **

本文探讨了少林寺接纳新僧的过程,包括评估新僧的佛学理解和战斗技能,最终通过与老僧的战斗来确定新僧资格。文章详细介绍了战斗记录的恢复方法,涉及使用map数据结构来匹配新僧与老僧的战斗等级。

题意:

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.

map的这种用法还没见过呢,下次重拍一遍

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <queue>
 7 #include <set>
 8 #include <map>
 9 #include <string>
10 #include <math.h>
11 #include <stdlib.h>
12 using namespace std;
13 
14 int main()
15 {
16     map<int,int>mp;
17     int n;
18     while(scanf("%d",&n) == 1 && n)
19     {
20         mp.clear();
21         mp[1000000000] = 1;
22         int u,v;
23         while(n--)
24         {
25             scanf("%d%d",&u,&v);
26             printf("%d ",u);
27             map<int,int>::iterator it = mp.lower_bound(v);
28             if(it == mp.end())
29             {
30                 it--;
31                 printf("%d\n",it->second);
32             }
33             else
34             {
35                 int t1 = it->first;
36                 int tmp = it->second;
37                 if(it != mp.begin())
38                 {
39                     it--;
40                     if(v - it->first <= t1 - v)
41                     {
42                         printf("%d\n",it->second);
43                     }
44                     else printf("%d\n",tmp);
45                 }
46                 else printf("%d\n",it->second);
47             }
48             mp[v] = u;
49         }
50     }
51     return 0;
52 }
2015/7/6

 

转载于:https://www.cnblogs.com/cnblogs321114287/p/4624861.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值