HDU 4585 Shaolin (STL)
没想到map还有排序功能,默认按照键值从小到大排序
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdlib>
using namespace std; int main() {
int n;
int id,g;
while(scanf("%d",&n) && n) {
map<int,int>m;
m[1000000000] = 1;
for(int i=1; i<=n; ++i) {
scanf("%d%d",&id,&g);
printf("%d ",id);
map<int,int> ::iterator it;
it = m.lower_bound(g); // 二分找第一个大于等于g的位置,如果没有,则返回末尾位置
if(it == m.end()) {
it -- ;
printf("%d\n",it->second);
} else {
if(it == m.begin()) {
printf("%d\n",it->second);
} else {
int pos = it->first;
int tmp = it->second;
it --;
printf("%d\n",(pos - g) < (g - it->first) ? tmp : it->second);
}
}
m[g] = id;
}
}
return 0;
}
HDU 4585 Shaolin (STL)的更多相关文章
- hdu 4585 Shaolin(STL map)
Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...
- 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)
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 (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 treap
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem ...
- A -- HDU 4585 Shaolin
Shaolin Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java clas ...
随机推荐
- [python 源码]整数对象的创建和维护
刚开始学python时候,发现一个很迷惑的现象,一直到看了源码后才知道了: >>> a=6 >>> b=6 >>> a is b True 想用同 ...
- 1004 Counting Leaves (30)(30 point(s))
problem A family hierarchy is usually presented by a pedigree tree. Your job is to count those famil ...
- hdu1527下沙小面的(二)
B - 下沙小面的(2) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Django-url路由映射与views逻辑处理
一.URL路由映射 路由映射模块,主要完成url与views视图函数的映射.当一个url请求到来时,会按照这个模块中的url地址从上到下进行匹配,如果匹配成功,将执行映射试图中的函数:反之将返回404 ...
- python日常碎碎念--PIL
昨天在处理网站相关图片的时候,发现图片都大小不一样,虽然一下就能想起PIL这个库,但是用法却不记得了. 简单记录一下用法. 可以直接用 Image.open 来打开图片,PIL库为这个文件对象提供了各 ...
- 记一次完整的pc前端整站开发
我所做的项目是一个线上的旅游平台,当然不是大家耳熟能详的那些旅游平台了,项目刚开始也没有必要去评价它的好坏,在这里我就不多说了~这是线上地址有兴趣的同学可以去看看(www.bookingctrip.c ...
- 华为S5300系列升级固件S5300SI-V100R005C01SPC100.cc
这个固件附带了web,注意,这个插件是升级V200的必经固件,所以必须升级为此固件之后才能往下升级. 升级小插曲: 1.升级的使用使用Windows,不要用Mac或者Linux,因为从Mac/Linu ...
- Bus Blaster
http://dangerousprototypes.com/docs/Bus_Blaster Bus Blaster v2 is an experimental, high-speed JTAG d ...
- patch 用法
diff -Nrua a b > c.patch 实例说明: --- old/modules/pcitable Mon Sep 27 11:03:56 1999 +++ new/modules/ ...
- C#中,为什么在值类型后面加问号
在C#中,声明一个值类型或引用类型的变量,无论是否给这个变量赋初值,该变量都有默认值: 比如声明引用类型变量: string a,其等效于string a = null,string的默认值为null ...