hdu 4585 Shaolin(STL map)
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.
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.
2 1
3 3
4 2
0
3 2
4 2
题意:讲的是一群无聊的和尚在比武,当来了一个新和尚时要挑选一个战斗力与他最接近的老和尚比武,
如果有两个老和尚和尚与他的战斗力的绝对值相等,则选择战斗力比他小的。
输出这个新和尚的编号和与他比武的老和尚的编号
直接用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)的更多相关文章
- HDU 4585 Shaolin (STL)
没想到map还有排序功能,默认按照键值从小到大排序 #include <cstdio> #include <iostream> #include <cstring> ...
- HDU 4585 Shaolin(STL map)
Shaolin Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit cid= ...
- 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: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- [HDU 4585] Shaolin (map应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585 题目大意:不停的插入数字,问你跟他相距近的ID号.如果有两个距离相近的话选择小的那个. 用map ...
- 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(map应用+二分)
题目大意:原题链接 初始少林最开始只有一个老和尚,很多人想进少林,每个人有一个武力值,若某个人想进少林,必须先与比他早进去的并且武力值最接近他的和尚比武, 如果接近程度相同则选择武力值比他小的,按照进 ...
- HDU 2112 HDU Today(STL MAP + Djistra)
题目链接:HDU Today 立即集训要開始,抓紧时间练练手,最短路的基础题,第一次用STL的map 题目非常水,可是错了N遍.手贱了.本题不优点理的就是把地名转化为数字 #include <i ...
随机推荐
- Java基础知识强化71:正则表达式之基本规则 和 常用正则表达式
1. 基本规则: A:字符 x 字符 x.举例:'a'表示字符a \\ 反斜线字符. \n 新行(换行)符 ('\u000A') \r 回车符 ('\u000D') B:字符类 [abc] a.b 或 ...
- 关于坑爹的PopupWindow的“阻塞”争议问题:Android没有真正的“阻塞式”对话框
请先允许我对网上某些没经过亲自实践人云亦云的同志呵呵... 那么开始正文,首先"阻塞"这个词本身就存在理解上的差异! 一般我们理解的阻塞,是阻塞了某个线程,即代码执行到这里后等待这 ...
- Linux GRUB 2及修改默认启动项
The GRUB 2 boot loader makes sure that you can boot Linux. GRUB 2 is installed in the boot sector of ...
- linux中内核的一个不错的参数somaxconn
导读:在linux中,/proc/sys/net/core/somaxconn这个参数,linux中内核的一个不错的参数somaxconn 看下其解析: 对于一个TCP连接,Server与Client ...
- 小学生之使用Mybatis反向生成dao,entity,xml
本小学生刚进公司的时候,就一顿装逼,不管别人问我啥我都会说:"会"!毕竟在公司吗,什么都要装,不要别人看出你的底细.不过有一天,听说用Mybatis可以反向生成dao(第一次听说) ...
- svg学习笔记
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- javascript判断浏览器
function getExplorer() { //IE if (navigator.userAgent.indexOf("MSIE")>=0) { } //Firefox ...
- QT5-控件-QDial(表盘控件)
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDial> class ...
- KVM virt-manager使用.
本来不想写,但是觉得教程就应该详细点..所以又有了这篇文章..主要是对图形化kvm管理的一些说明 接着上一篇... 1.Virtual Machine Manager 摘要: 打开Virtual Ma ...
- 前台任意页面调用自定义字段选项 box 单选 多选方法及查询
在模板页增加函数,函数写法比较特殊,但是v9模板引擎nb,能够识别 <? function xbox($field,$na){ $a=p ...