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 (STL)

    没想到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. [HDU 4585] Shaolin (map应用)

    题目链接: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(map应用+二分)

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

  9. HDU 2112 HDU Today(STL MAP + Djistra)

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

随机推荐

  1. Android 百度地图 SDK v3.0.0 (三) 添加覆盖物Marker与InfoWindow的使用

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37737213 上篇博客已经实现了地图的定位以及结合了方向传感器用户路痴定位方向, ...

  2. Java基础知识强化之IO流笔记01:异常的概述和分类

     IO流操作的时候会出现很多问题,java中叫作异常,所以我们先介绍一下异常: 1. 程序的异常:Throwable(Throwable类是java中所有异常或错误的超类) (1)严重问题:Error ...

  3. ProGuard 代码混淆

    简介 Java代码是非常容易反编译的.为了很好的保护Java源代码,我们往往会对编译好的class文件进行混淆处理. ProGuard是一个混淆代码的开源项目.它的主要作用就是混淆,当然它还能对字节码 ...

  4. poj 1964 Cow Cycling(dp)

    /* 一开始想的二维的 只维护第几只牛还有圈数 后来发现每只牛的能量是跟随每个状态的 所以再加一维 f[i][j][k]表示第i只牛 领跑的j全 已经消耗了k体力 转移的话分两类 1.换一只牛领跑 那 ...

  5. FastReport 动态修改连接字符串

    代码如下: Report rp = new Report(); rp.Load(@"Print\aa.frx"); rp.Dictionary.Connections[0].Con ...

  6. Windows Native API

    http://en.wikipedia.org/wiki/Native_API Windows 的原生 API 函数通常在系统启动时(这里其他 Windows 组件还不可用).kernel32.dll ...

  7. 织梦DEDECMS {dede:field name='position'/}标签增加其它属性的

    在默认情况下,织梦(DedeCms)系统当前位置的调用标签为: {dede:field name='position'/} 在这种默认的情况下,生成后的代码大致为如下格式: 主页 > 应用软件 ...

  8. IE下判断IE版本的语句

    <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见   <!--[if lte IE 7]> <![endif]--> ...

  9. JSP学习笔记(1)

    JSP本质就是一个servlet,当第一次接受到客户端请求时会被编译成对应的servlet,且对应的每个servlet在容器中只要一个实例. 1.1.JSP注释 <%-- JSP注释部分 --& ...

  10. shell中if做比较

    比较两个字符串是否相等的办法是: if [ "$test"x = "test"x ]; then 这里的关键有几点: 1 使用单个等号 2 注意到等号两边各有一 ...