题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585

题意:

第一个人ID为1,战斗力为1e9。

给定n,给出n个人的ID和战斗力。

每个人必须和战斗力最接近他的人战斗,如果一样接近就和ID小的人战斗。

注意:不建议在比较时用很多it--和it++

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
map<int,int>mp;
mp[1e9]=;
for(int i=;i<n;i++)
{
int k,g;
cin>>k>>g;
mp[g]=k;
map<int,int>::iterator it=mp.find(g),it2,it3;
it2=it;it2++;
it3=it;it3--;
if(it==mp.begin())cout<<k<<" "<<it2->second<<endl;
else if(it==mp.end())cout<<k<<" "<<it3->second<<endl;
else
{
int tmp=it->first,tmp2=it2->first,tmp3=it3->first; if(abs(tmp3-tmp)<=abs(tmp-tmp2))cout<<k<<" "<<it3->second<<endl;
else cout<<k<<" "<<it2->second<<endl;
}
}
}
return ;
}

hdu4585Shaolin的更多相关文章

随机推荐

  1. linux No module named yum错误的解决办法

    linux No module named yum错误的解决办法 肯定是yum的版本与当前python的版本不一致造成的 <pre>所以修改yum的配置,修改文件: vim /usr/bi ...

  2. 基于docker搭建Jenkins+Gitlab+Harbor+Rancher架构实现CI/CD操作(续)

    说明:前期的安装,请转向https://www.cnblogs.com/lq-93/p/11824039.html (4).查看gitlab镜像是否启动成功 docker inspect  容器id  ...

  3. SpringBoot Web篇(二)

    摘要 继上一篇 SpringBoot Web篇(一) 文件上传 当我们服务器需要接收用户上传的文件时,就需要使用MultipartFile作为参数接收文件.如下: @PostMapping(" ...

  4. Java把一个文件,输出成多个文件

    前言:我有一个出租车轨迹的txt文本,其中包括多条轨迹.我想把这个文本按照单条轨迹输出出来,每条轨迹放在一个txt文本中. 思路:重要问题就集中在,如何动态的指定输出文件的名字.我想到了StringB ...

  5. redis集群节点重启后恢复

    服务器重启后,集群报错: [root@SHH-HQ-NHS11S nhsuser]# redis-cli -c -h ip -p 7000ip:7000> set cc dd(error) CL ...

  6. T-SQL, Part III: Check table's existance

    There are several approaches to achieve so. Just list out all approaches I have tried: Approach 1: s ...

  7. 插入排序的代码实现(C语言)

    void insert_sort(int arr[], int len) { for (int i = 1; i < len; ++i) { if (arr[i] < arr[i - 1] ...

  8. nyoj 412 Same binary weight ()

    Same binary weight 时间限制:300 ms  |  内存限制:65535 KB 难度:3   描述 The binary weight of a positive  integer ...

  9. nyoj 78-圈水池 (凸包)

    78-圈水池 内存限制:64MB 时间限制:3000ms 特判: No 通过数:5 提交数:6 难度:4 题目描述: 有一个牧场,牧场上有很多个供水装置,现在牧场的主人想要用篱笆把这些供水装置圈起来, ...

  10. 小白学 Python 爬虫(3):前置准备(二)Linux基础入门

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 Linux 基础 CentOS 官网: https: ...