hdu 4585 Shaolin(STL map)

时间:2021-12-16 04:39:57
Problem Description
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
 
 
Source

题意:讲的是一群无聊的和尚在比武,当来了一个新和尚时要挑选一个战斗力与他最接近的老和尚比武,       

      如果有两个老和尚和尚与他的战斗力的绝对值相等,则选择战斗力比他小的。     

      输出这个新和尚的编号和与他比武的老和尚的编号   

      直接用map标记就行了,

      不过还是WA了好几次,说明自己还是很差啊!

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<map>
using namespace std;
#define N 100006
int n;
map<int,int>mp;
map<int,int>::iterator it,it2;
int main()
{
while(scanf("%d",&n)==1 && n)
{
mp.clear();
mp[1000000000]=1;
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
it=mp.lower_bound(y);
if(it==mp.begin())//当新的只能排在第一位时,直接输出第一个
{
printf("%d %d\n",x,it->second);
}
else
{
it2=it;
it--;
if(abs(y-it->first)>abs(y-it2->first))
printf("%d %d\n",x,it2->second);
else
printf("%d %d\n",x,it->second);
}
mp[y]=x;
}
}
return 0;
}

hdu 4585 Shaolin(STL map)的更多相关文章

  1. HDU 4585 Shaolin &lpar;STL&rpar;

    没想到map还有排序功能,默认按照键值从小到大排序 #include <cstdio> #include <iostream> #include <cstring> ...

  2. HDU 4585 Shaolin(STL map)

    Shaolin Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit cid= ...

  3. HDU 4585 Shaolin(Treap找前驱和后继)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Su ...

  4. HDU 4585 Shaolin (STL map)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  5. &lbrack;HDU 4585&rsqb; Shaolin &lpar;map应用&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585 题目大意:不停的插入数字,问你跟他相距近的ID号.如果有两个距离相近的话选择小的那个. 用map ...

  6. HDU 4585 Shaolin(水题,STL)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  7. HDU 4585 Shaolin (STL)

    Shaolin Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Sub ...

  8. HDU 4585 Shaolin&lpar;map应用&plus;二分&rpar;

    题目大意:原题链接 初始少林最开始只有一个老和尚,很多人想进少林,每个人有一个武力值,若某个人想进少林,必须先与比他早进去的并且武力值最接近他的和尚比武, 如果接近程度相同则选择武力值比他小的,按照进 ...

  9. HDU 2112 HDU Today(STL MAP &plus; Djistra)

    题目链接:HDU Today 立即集训要開始,抓紧时间练练手,最短路的基础题,第一次用STL的map 题目非常水,可是错了N遍.手贱了.本题不优点理的就是把地名转化为数字 #include <i ...

随机推荐

  1. 【Unity3D游戏开发】之常用代码 &lpar;十二&rpar;

    //创建一个名为"Player"的游戏物体 //并给他添加刚体和立方体碰撞器. player=new GameObject("Player"); player. ...

  2. windows下mysql主从同步备份步骤

    目的:有两台MySQL数据库服务器A和B,使A为主服务器,B为从服务器,初始状态时,A和B中的数据信息相同,当A中的数据发生变化时,B也跟着发生相应的变化,使得A和B的数据信息同步,达到备份的目的. ...

  3. EASYUI&plus;MVC4通用权限管理平台--前言

    经过多年的管理信息系统的开发工作,吸取了工作中遇到的一些问题,经过自己的总结,形成了一套比较完整的管理信息系统的通用权限管理基础开发平台. 在软件的开发过程中我们首先需要解决的是UI问题,其次是浏览器 ...

  4. 用hibernate自动创建mysql表,添加失败org&period;hibernate&period;exception&period;SQLGrammarException

    今天遇到了一个很坑人的问题,从昨晚一直搞到今天早上,终于发现了,先整理下: [背景]:利用hibernate自动给mysql创建一个表,然后为表里面添加一行记录,非常的简单(当然其中还涉及到sprin ...

  5. ajax请求返回json数据弹出下载框的解决方法

    将返回的Content-Type由application/json改为text/html. 在struts2下: <action name="XXXAjax" class=& ...

  6. Android多项目依赖在Eclipse中无法关联源代码的问题解决 Ctril 点不进去的解决方法

    1. 使用快捷键:Ctrl+shift+R,在弹出框中输入.classpath  找到被作为library引入的那个.classpath文件. 2.将kind="src" path ...

  7. BZOJ 2329&colon; &lbrack;HNOI2011&rsqb;括号修复&lpar; splay &rpar;

    把括号序列后一定是))))((((这种形式的..所以维护一个最大前缀和l, 最大后缀和r就可以了..答案就是(l+1)/2+(r+1)/2...用splay维护,O(NlogN). 其实还是挺好写的, ...

  8. js中 substr&lpar;&rpar;&comma; substring&lpar;&rpar;&comma; slice&lpar;&rpar;的区别

    一.作用 三者都是基于原字符串创建新字符串的方法. 接收一到两个参数,第一个参数截取字符串的开始位置(字符下标,从0开始),第二个参数因方法不同而不同,后面不同点会说到. 另外,三个方法都不会修改原字 ...

  9. js动态生成二维码

    一.使用jquery.qrcode生成二维码 1.首先在页面中加入jquery库文件和qrcode插件 <script type="text/javascript" src= ...

  10. Linux环境系搭建Git服务器过程全纪录

    Last :: from 139.199.180.186 [root@VM_219_131_centos ~]# yum install curl-devel expat-devel gettext- ...