题意描述

Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every year, trying to be a monk there. The master of Shaolin evaluates a young man mainly by his talent on understanding the Buddism scripture, but fighting skill is also taken into account.
When a young man passes all the tests and is declared a new monk of Shaolin, there will be a fight , as a part of the welcome party. Every monk has an unique id and a unique fighting grade, which are all integers. The new monk must fight with a old monk whose fighting grade is closest to his fighting grade. If there are two old monks satisfying that condition, the new monk will take the one whose fighting grade is less than his.
The master is the first monk in Shaolin, his id is 1,and his fighting grade is 1,000,000,000.He just lost the fighting records. But he still remembers who joined Shaolin earlier, who joined later. Please recover the fighting records for him.

依次给出和尚序列,寻找与自己的战力相差最小的和尚,输出战斗的顺序

思路

由于之前只是简单学了map的使用,对于map的遍历没有研究过。这道题也是现学现做的。由于id和战力的唯一性,所以我们可以使用map来进行映射,由于map是有序的,所以map对应的映射可以为[战力:id],然后每次输入后利用lower_bound来寻找最接近的,然后比较即可。

AC代码

#include<bits/stdc++.h>
#define x first
#define y second
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=1e5+10;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
void solve(){int n;while(cin>>n && n){vector<PII> ans;map<int,int> mp;map<int,int>::iterator it1,it2,it3;mp[1000000000]=1;for(int i=0;i<n;i++){int idx,power;cin>>idx>>power;it1=mp.lower_bound(power);if(it1==mp.begin()){ans.push_back({idx,it1->second});}else{it2=it1;it3=--it1;if(abs(it2->first-power)>=abs(it3->first-power)){ans.push_back({idx,it3->second});}else ans.push_back({idx,it2->second});}mp[power]=idx;}for(int i=0;i<ans.size();i++) cout<<ans[i].x<<' '<<ans[i].y<<endl;}
}
int main(){IOS;solve();return 0;
}

Shaolin(map)相关推荐

  1. Shaolin(map+iterator) HDU - 4585

    Shaolin(map+iterator) HDU - 4585 少林寺以武僧而闻名.每年都有很多年轻人去少林寺当和尚.少林的主人评估一个年轻人主要通过他的人才了解佛教经文,但武功也考虑在内. 当一个 ...

  2. 【机器学习基本理论】详解最大似然估计(MLE)、最大后验概率估计(MAP),以及贝叶斯公式的理解

    [机器学习基本理论]详解最大似然估计(MLE).最大后验概率估计(MAP),以及贝叶斯公式的理解 https://mp.weixin.qq.com/s/6H0gmMWvTExySMraroLVlQ 最 ...

  3. 【机器学习基本理论】详解最大后验概率估计(MAP)的理解

    [机器学习基本理论]详解最大后验概率估计(MAP)的理解 https://mp.weixin.qq.com/s/dQxN46wEbFrpvV369uOHdA 最大似然估计(Maximum likeli ...

  4. 2021-10-16 集合(set)与映射(map) 恋上数据结构笔记

    文章目录 集合(Listset and Treeset) 集合时间复杂度分析 Treeset的局限性 映射(Map) Map与Set 集合(Listset and Treeset) 概念:就是不存储重 ...

  5. properties(map)增.删.改.查.遍历

    import java.util.Map; import java.util.Properties; import java.util.Set;/*** properties(map)增.删.改.查. ...

  6. 中国磷酸一铵(MAP)行业市场供需与战略研究报告

    出版商:贝哲斯咨询 获取报告样本: 企业竞争态势 磷酸一铵(MAP)市场报告涉及的主要国际市场参与者有Mosaic Company.Potash.Mitsui Chemicals.URALCHEM.J ...

  7. Tricks(十七) —— 数组与字典(map)

    (1)数组也能实现一种映射(map),将下标映射为下标对应的值,数组和字典甚至映射的形式都是一样的,都是使用中括号. arr[0] = 1; m["InsideZhang"] = ...

  8. 【转】最大后验概率(MAP)- maximum a posteriori

    最大后验概率(MAP)- maximum a posteriori var $tag='map,最大后验概率,杂谈'; var $tag_code='55bc272ff71193850b39cc269 ...

  9. sizzle.js学习笔记利用闭包模拟实现数据结构:字典(Map)

    sizzle.js学习笔记利用闭包模拟实现数据结构:字典(Map) 这几天学习和查看了jQuery和Property这两个很流行的前端库的御用选择器组件Sizzle.js的源代码,收获还是相对多的!之 ...

  10. 最大似然估计(MLE),最大后验概率估计(MAP),贝叶斯估计入门讲解

    已知数据X,去拟合某个概率模型的参数θ,是最基本的机器学习过程. 本文将入门讲解3个最基本的方法:最大似然估计(Maximum Likelihood Estimation,简称MLE),最大后验概率估 ...

最新文章

  1. Erdaicms旅游网站系统微信和手机端分销系统正式上线发布啦
  2. 4种动态加载JS的方法
  3. Nginx动静分离-tomcat
  4. CH - 6901 骑士放置(二分图最大独立集-二分图最大匹配+奇偶拆点)
  5. 在腾讯云云函数计算上部署.NET Core 3.1
  6. 轻量级Web应用程序:PrimeFaces(JSF)+ Guice + MyBatis(第1部分)
  7. 导出配置_Lua配置表导出优化
  8. 父组件给子组件传值方法_【Vue】小学生都能看懂的子父组件传值
  9. JavaScript数组方法终极指南-地图
  10. Java 进阶:集合框架2
  11. 自注意力机制_自注意力机制在计算机视觉中的应用【附PPT与视频资料】
  12. Tcl Tutorial 笔记8 · proc
  13. CAXA 分解命令x 解决不能选中图形问题。
  14. 【读】自动文摘——预备
  15. 学员管理系统(完整版)
  16. worldwind 三维模型加载优化总结
  17. 哈夫曼树的构造与哈夫曼编码
  18. 南开大学计算机学院博士毕业要求,南京大学博士研究生申请学位科研成果基本要求...
  19. 摩伴windows桌面服务器,魔伴windows桌面
  20. html5画直线箭头,HTML5 canvas画带箭头的虚线

热门文章

  1. 松翰单片机数码管c语言,松翰单片机定时中断数码管程序
  2. CocosCreator-动态生成3种敌人
  3. bind搭建智能DNS
  4. FoveaBox(Beyond Anchor-based Object Detector) 学习笔记
  5. c语言变量报存在bss段,C语言初始化——bss段初始化、跃入C、C与汇编
  6. DocumentBuilderFactory.newInstance() 异常解决
  7. USB-PD 协议解析 - 简单易懂协议详解
  8. 一文读懂:DNA甲基化的作用及各种高通量检测方法比较
  9. [单片机框架][bsp层][AT32F415][bsp_adc] adc配置和使用
  10. DEVC++安装后编程运行时老是提示“源文件未编译”