#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
map<int ,int>mp;
int n;
while(~scanf("%d",&n)&&n)
{
int id,fg;
mp[]=;
for(int i=; i<n; i++)
{
scanf("%d %d",&id,&fg);
mp[fg]=id;
map<int ,int>::iterator it=mp.find(fg),it1;
if(it==mp.begin())
printf("%d %d\n",id,(++it)->second);
else
{
it1=it;
if(abs((--it)->first-fg)<=abs((++it1)->first-fg))
printf("%d %d\n",id,(it)->second);
else
printf("%d %d\n",id,(it1)->second); }
}
mp.clear(); }
return ;
}

map是有序的好处

HDU4329的更多相关文章

随机推荐

  1. Linux-./configure: error: the HTTP rewrite module requires the PCRE library.

    这个问题是要解决: yum -y install pcre-devel 然后在yum的时候发现出错.问题是我的linux不能上网. 这个问题搞得烦死了.和主机能ping.但是就是不能上网: ping ...

  2. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  3. C语言中struct位域的定义和使用

    位域的定义和使用 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又 ...

  4. jquery版滑块导航栏

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <script src ...

  5. 如何设置Oracle客户端与服务器的字符集一致

    查看 Oracle 服务器字符集 select userenv('language') from dual; 设置Oracle客户端字符集 添加环境变量NLS_LANG 值与服务器的Oracle服务器 ...

  6. PHP SPL(PHP 标准库)

    一.什么是SPL? SPL是用于解决典型问题(standard problems)的一组接口与类的集合.(出自:http://php.net/manual/zh/intro.spl.php) SPL, ...

  7. bzoj1901

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7218  Solved: 3000[Su ...

  8. LAMP(1) 在VirtualBox里安装Ubuntu Server

    问题0.虚拟机中安装lamp环境 问题解决: 来自百度经验 问题1. 用putty远程登陆linux系统,显示network error connection refused 问题解决 问题2. my ...

  9. Activity详解生命周期(Android)

    Activity是Android组件中最基本也是最为常见用的四大组件(Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器)之 ...

  10. js获取当前系统时间

    Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份 ...