HDU_4585_Shaolin
2024-04-01 02:47:39
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;
}
最新文章
- 个性化推荐之召回的方法
- 第一课 计算机网络的分类,第一课-计算机网络基本组成
- 为了建设我们的飞鸽传书2011
- 关于win10家庭版不能开启虚拟机的问题
- android小程序:计算圆面积
- ORAN专题系列-5:5G O-RAN 一体式小基站硬件白盒化的参考架构
- bootstrap表单样式
- 七、决策树算法和集成算法
- 每周博客 农历二月二(理发的日子)
- Cocos Creator AnySDK支付问题
- STM32低功耗模式
- 全国少年乒乓球锦标赛
- 自定义vue3.0日历组件
- 非此即彼的逻辑错误_英语逻辑错误一览
- 如何优化你在百度搜索中的排行
- homebrew是个啥
- shell for 循环
- RAD0.1 RB.1/.2
- springboot 导入excel(数据批量导入)
- Unity3D鼠标&Touch拖拽控制节点绕任意轴旋转的实现
热门文章
- 域名管理系统DNS(Domain Name System)
- 删除文件出现“文件正在使用或正在打开”
- 【踩坑记录】.bss段;.bss段到底占不占目标文件的空间,有没有记录对应信息。
- 自然语言处理总复习(五)—— 词义消歧
- Flash音乐暂停播放按钮
- 在线计算机表格制作,excel表格制作,教您excel怎么制作表格
- movie计算机英语作文,my favorite movie英语作文100字
- 16.	Zigbee应用程序框架开发指南 - 扩展ZigBee Cluster Library (ZCL)
- 数据结构 严薇敏 单链表(无头结点)的实现(增 删 改 查)及其使用方法详解
- 如何使用计算机对文件修改密码,文件夹怎么设置密码?怎么给文件夹设置密码?...