没想到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)的更多相关文章

  1. hdu 4585 Shaolin(STL map)

    Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...

  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)

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

  5. HDU 4585 Shaolin (STL)

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

  6. HDU 4585 Shaolin (STL map)

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

  7. [HDU 4585] Shaolin (map应用)

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

  8. hdu 4585 Shaolin treap

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

  9. A -- HDU 4585 Shaolin

    Shaolin Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java clas ...

随机推荐

  1. vsftp 虚拟用户+MySQL认证独立家目录

    centos7 系统 安装包 yum -y install mariadb vsftpd openssl-devel  mysql-devel  pam-devel yum -y groupinsta ...

  2. Kubernetes网络模型概念

    Kubernetes网络模型 Kubernetes网络模型设计的一个基础原则是:每个Pod都拥有一个独立的IP地址,而且假定所有Pod都在一个可以直接连通的.扁平的网络空间中.所以不管它们是否运行在同 ...

  3. 02-c#基础之01-基础语法(一)

    1.注释符 1)注销 2) 解释 2.C#中的3种注释符 1)单行注释// 2)多行注释/*要注释的内容*/ 3)文档注释///多用来解释类或者方法 2.VS中的快捷键

  4. BZOJ.4516.[SCOI2016]幸运数字(线性基 点分治)

    题目链接 线性基可以\(O(log^2)\)暴力合并.又是树上路径问题,考虑点分治. 对于每个点i求解 LCA(u,v)==i 时的询问(u,v),只需求出这个点到其它点的线性基后,暴力合并. LCA ...

  5. BZOJ3522&4543 [POI2014]Hotel加强版 长链剖分

    上上周见fc爷用长链剖分秒题 于是偷偷学一学 3522的数据范围很小 可以暴力枚举每个点作为根节点来dp 复杂度$O(n^2)$ 考虑令$f[x][j]$表示以$x$为根的子树内距离$x$为$j$的点 ...

  6. Loj10167 HDU2089 不要62

    题目描述 杭州人称那些傻乎乎粘嗒嗒的人为 626262(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士 ...

  7. php安装配置

    Content 0.序 1.安装前准备 2.安装PHP 3.配置php-fpm 0.序 本文主要是记录php在 Centos下的安装配置 .文中如无特别说明.表示php-5.6.31代码目录. 1.安 ...

  8. spring---aop(7)---Spring AOP中expose-proxy介绍

    写在前面 expose-proxy.为是否暴露当前代理对象为ThreadLocal模式. SpringAOP对于最外层的函数只拦截public方法,不拦截protected和private方法(后续讲 ...

  9. How to Make Portable Class Libraries Work for You

    A Portable Class Library is a .NET library that can be used (in binary form, without recompiling) on ...

  10. Using Windows Server 2012 Backup for Hyper-V Virtual Machines. Error 80780176 - The specified component was not reported by the VSS writer.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/1a1e0066-f421-43d6-970b-1e20e674cdf9 ...