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 ...
随机推荐
- [ 原创 ]Centos 7.0下启动 Tomcat8.5.15
1.打开8080端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent 2.重启防火墙 firewall-cmd --relo ...
- tftp协议
<前言> 嵌入式开发是一个交叉开发的模式,需要将宿主机上的文件烧写到目标机上. 方式: JTAG USB 串口 网络 <tftp下载> 首先需要将宿主机架成一个TFTP的服务器 ...
- 【WIN10】程序內文件讀取與保存
DEMO下載:http://yunpan.cn/cFHIZNmAy4ZtH 访问密码 cf79 1.讀取與保存文件 Assets一般被認為是保存用戶文件數據的地方.同時,微軟還支持用戶自己創建文件夾 ...
- CF696B Puzzles 期望
显然可以树形$dp$ 令$f[i]$表示$i$号节点的期望时间戳 不妨设$fa$有$k$个子节点,对于$i$的子节点$u$,它是第$j(1 \leqslant j \leqslant k)$个被访问的 ...
- (转)park1.0.0生态圈一览
转自博客:http://www.tuicool.com/articles/FVBJBjN Spark1.0.0生态圈一览 Spark生态圈,也就是BDAS(伯克利数据分析栈),是伯克利APMLab实验 ...
- 移动web开发经验总结(1)
1.<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-sca ...
- matlab 乱七八糟求最大值~
w=rand(,) [a b]=size(w); x=; maxw=w(,); :a :b if w(k,d)>maxw maxw=w(k,d); end end end disp(['haha ...
- python编译模块为2禁制
编译模块为2禁制yum -y install python26-setuptoolseasy_install -U setuptools# cd /usr/lib64/python2.6# easy_ ...
- ARM ® and Thumb ®-2 指令系统
指令表关键词 Rm {, <opsh>} 寄存器移位方式,将寄存器的移位结果作为操作数而Rm值保持不变 <Operand2> 灵活的使用第二个操作数. ...
- 读书笔记-APUE第三版-(8)进程控制
进程ID 每一个进程都有一个唯一的进程ID.几个特殊进程: 0号进程是内核进程,一般是调度进程swapper. 1号进程init,是用户进程(以root权限执行/sbin/init),负责初始化. 几 ...