题目大意:原题链接

初始少林最开始只有一个老和尚,很多人想进少林,每个人有一个武力值,若某个人想进少林,必须先与比他早进去的并且武力值最接近他的和尚比武,

如果接近程度相同则选择武力值比他小的,按照进入少林的先后顺序,求出每个和尚进去的时候应当和哪个和尚比武。

#include<map>
#include<iostream>
using namespace std;
int main()
{
int n,id,g;
map<int,int>::iterator it,p1,p2;
while(scanf("%d",&n),n){
map<int,int> m;
m[]=;
while(n--){
scanf("%d%d",&id,&g);//first为战斗值,second为编号
it=m.lower_bound(g);
if(it==m.begin())
cout<<id<<' '<<it->second<<endl;
else{
p1=it,p2=--it;
if(p1->first-g>=g-p2->first)//等号是为了当两边相等时输出战斗值较低的
cout<<id<<' '<<p2->second<<endl;
else
cout<<id<<' '<<p1->second<<endl;
}
m[g]=id;//g为战斗值,id为编号
}
}
}

HDU 4585 Shaolin(map应用+二分)的更多相关文章

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

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

  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 map)

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

  5. HDU 4585 Shaolin (STL map)

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

  6. HDU 4585 Shaolin (STL)

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

  7. hdu 4585 Shaolin treap

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

  8. A -- HDU 4585 Shaolin

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

  9. hdu 4585 map **

    题意: Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every ...

随机推荐

  1. [转]Loadrunner Error code 10053 & Tomcat 连接器(connector)优化

    LoadRunner提示错误:Error : socket0 - Software caused connection abort. Error code : 10053. 在今天的测试过程中发现,s ...

  2. Visual Studio Code调试node.js:无法在PATH上找到运行时的node

    首先,环境变量Path中加入nodejs的路径: 验证nodejs是否已经加入环境变量: 接着,重新启动Visual Studio Code, 试一下,是不是好了~   附录:Visual Studi ...

  3. 采用std::thread 替换 openmp

    内容转换的,具体详见博客:https://cloud.tencent.com/developer/article/1094617 及对应的code:https://github.com/cpuimag ...

  4. leetcode -- Best Time to Buy and Sell Stock III TODO

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  5. 关于recycler遇到的问题

    1.//设置recyclerView不能点击myLayoutManager.setScrollEnabled(false);class MyLayoutManager extends LinearLa ...

  6. Android测试:从零开始2——local单元测试

    上一篇分析了android项目的测试分类,这一篇讲local单元测试. 参考android官方文档. 测试前需要配置测试环境,新建项目后,目录下会出现app/src/test/java/文件夹,这个文 ...

  7. 一文彻底解决Ubuntu上PHP的安装以及版本切换

    Ubuntu上官方的源,比如 Ubuntu14.04 默认源中的是 PHP5.6.x.Ubuntu16.04 默认源中的是 PHP7.0.x,那么如果想在 Ubuntu16.04 上安装 PHP7.1 ...

  8. 170328、Maven+SpringMVC+Dubbo 简单的入门demo配置

    之前一直听说dubbo,是一个很厉害的分布式服务框架,而且巴巴将其开源,这对于咱们广大程序猿来说,真是一个好消息.最近有时间了,打算做一个demo把dubbo在本地跑起来先. 先copy一段dubbo ...

  9. 160613、MyBatis insert操作返回主键

    在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:如果业务层需要得到记录的主键时,可以通过配置的方式来完成这个功能,针对Sequence主键而言,在执行 ...

  10. 160513、nginx+tomcat集群+session共享(linux)

    第一步:linux中多个tomcat安装和jdk安装(略) 第二步:nginx安装,linux中安装nginx和windows上有点不同也容易出错,需要编译,这里做介绍 一.安装依赖 gcc open ...