HDU_4585_Shaolin
题意:少林寺招新,起初只有一个id为1武力值为1000000000的老和尚,现在要招一些新和尚,每个和尚入寺考核要和已经入寺的和尚比武且只和武力值与他相差最小的比武,当有两个和尚与他武力值差值相同时(比如大1和小1)便在这些差值相同的和尚里只和比他小的比武。
思路:用STL中的映射,用武力值作为键,然后找已入寺的和尚比武时用lower_bound函数查找。


#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>#define debug(x) cout << "--------------> " << x << endlusing namespace std;const double PI = acos(-1.0);
const double eps = 1e-10;
const long long INF = 0x7fffffff;
const long long MOD = 1000000007;int main()
{int n;while(scanf("%d", &n), n){map<int, int> m;map<int, int>::iterator it;int a, b;m[1000000000] = 1;for(int i = 0; i < n; ++i){scanf("%d%d", &a, &b);printf("%d ", a);it = m.lower_bound(b);if(it == m.begin() || it == m.end()){printf("%d\n", it->second);}else{//map按键值默认排序int a1 = it->first, b1 = it->second;it--;int a2 = it->first, b2 = it->second;if((b-a2) <= (a1-b)){printf("%d\n", b2);}elseprintf("%d\n", b1);}m[b] = a;}}return 0;
}

最新文章

  1. 个性化推荐之召回的方法
  2. 第一课 计算机网络的分类,第一课-计算机网络基本组成
  3. 为了建设我们的飞鸽传书2011
  4. 关于win10家庭版不能开启虚拟机的问题
  5. android小程序:计算圆面积
  6. ORAN专题系列-5:5G O-RAN 一体式小基站硬件白盒化的参考架构
  7. bootstrap表单样式
  8. 七、决策树算法和集成算法
  9. 每周博客 农历二月二(理发的日子)
  10. Cocos Creator AnySDK支付问题
  11. STM32低功耗模式
  12. 全国少年乒乓球锦标赛
  13. 自定义vue3.0日历组件
  14. 非此即彼的逻辑错误_英语逻辑错误一览
  15. 如何优化你在百度搜索中的排行
  16. homebrew是个啥
  17. shell for 循环
  18. RAD0.1 RB.1/.2
  19. springboot 导入excel(数据批量导入)
  20. Unity3D鼠标&Touch拖拽控制节点绕任意轴旋转的实现

热门文章

  1. 域名管理系统DNS(Domain Name System)
  2. 删除文件出现“文件正在使用或正在打开”
  3. 【踩坑记录】.bss段;.bss段到底占不占目标文件的空间,有没有记录对应信息。
  4. 自然语言处理总复习(五)—— 词义消歧
  5. Flash音乐暂停播放按钮
  6. 在线计算机表格制作,excel表格制作,教您excel怎么制作表格
  7. movie计算机英语作文,my favorite movie英语作文100字
  8. 16. Zigbee应用程序框架开发指南 - 扩展ZigBee Cluster Library (ZCL)
  9. 数据结构 严薇敏 单链表(无头结点)的实现(增 删 改 查)及其使用方法详解
  10. 如何使用计算机对文件修改密码,文件夹怎么设置密码?怎么给文件夹设置密码?...