hdu 4585 map **

时间:2021-12-16 04:39:57

题意:

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的这种用法还没见过呢,下次重拍一遍

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std; int main()
{
map<int,int>mp;
int n;
while(scanf("%d",&n) == && n)
{
mp.clear();
mp[] = ;
int u,v;
while(n--)
{
scanf("%d%d",&u,&v);
printf("%d ",u);
map<int,int>::iterator it = mp.lower_bound(v);
if(it == mp.end())
{
it--;
printf("%d\n",it->second);
}
else
{
int t1 = it->first;
int tmp = it->second;
if(it != mp.begin())
{
it--;
if(v - it->first <= t1 - v)
{
printf("%d\n",it->second);
}
else printf("%d\n",tmp);
}
else printf("%d\n",it->second);
}
mp[v] = u;
}
}
return ;
}

2015/7/6

hdu 4585 map **的更多相关文章

  1. &lbrack;HDU 4585&rsqb; Shaolin &lpar;map应用&rpar;

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

  2. HDU 4585 Shaolin&lpar;map应用&plus;二分&rpar;

    题目大意:原题链接 初始少林最开始只有一个老和尚,很多人想进少林,每个人有一个武力值,若某个人想进少林,必须先与比他早进去的并且武力值最接近他的和尚比武, 如果接近程度相同则选择武力值比他小的,按照进 ...

  3. HDU 4585 Shaolin(STL map)

    Shaolin Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit cid= ...

  4. C&plus;&plus; 学习小程序之 map 的用法

    1. map::at #include <iostream> #include <string> #include <map> using namespace st ...

  5. HDU 4585 Shaolin(Treap找前驱和后继)

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

  6. hdu 4585 Shaolin&lpar;STL map&rpar;

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

  7. HDU 4585 Shaolin (STL map)

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

  8. HDU 4585

    http://acm.hdu.edu.cn/showproblem.php?pid=4585 从原来的人中找出战斗数值最接近的,输出他们两人的序号 要在logn的复杂度完成查找,我用的是set,当然用 ...

  9. hdu 1800 (map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...

随机推荐

  1. iOS多线程知识总结--GCD

    iOS多线程知识总结--GCD 1. iOS中苹果提供4钟方案来帮助我们实现多线程: (1) 纯C语言的pthread,偏底层,需要程序员手动管理线程的生命周期,基本不用. (2) OC语言的NSTr ...

  2. spark二次排序

    数据: 2012,01,01,52012,01,02,452012,01,03,352012,01,04,102012,02,04,102012,02,03,182012,02,01,222012,0 ...

  3. jquery&period;validate&period;unobtrusive

    ASP.NET MVC Unobtrusive JavaScript 实现 onfocusout 验证, onfocusin 清除错误 在 ASP.NET MVC 中启用 Unobtrusive Ja ...

  4. &lbrack;原创&ast;精华&rsqb;一键发布ASP&period;NET Web安装程序&comma;搞WebForm的童鞋看过来&period;&period;&period;

          重要更新:鉴于很多小伙伴们说看不到图,我这边换了几个浏览器看了下,都看得到的,估计是网速问题,请耐心等待,另外,为了更好的方便大家学习,特此提供源码以及一个word文档,word文档就是本 ...

  5. java&period;io&period;IOException&colon; Invalid header signature&semi; read 0xE011BDBFEFBDBFEF&comma; expected 0xE11AB1A1E011CFD0

    根据网上的解释,这个表示poi读取excel(97-2003)的时候头文件被损坏了,正常的方式:能打开的话,另存一下即可,实在不行直接新建一个内容一样的 本人环境:eclipse部署到tomcat,e ...

  6. JAVA&lowbar;file&lpar;1&rpar;

    1.基本概念的理解 绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:C:xyz est.txt 代表了test.txt文件的绝对路径.http://www.s ...

  7. FND Debug Log&lpar;FND&lowbar;LOG&lowbar;MESSAGES&rpar;

    之前每个模块记录日志的方式都不同,都会把日志写到不同的文件中,对于User来说很麻烦,需要记住很多的配置,现在越来越多的模块使用FND Logging来存储日志,比如WIP,RCV,OAF...FND ...

  8. 10位时间戳使用moment转化为日期

    前情提要: 需要把后台传过来的10位时间戳转化格式为:‘YYYY-MM-DD HH:mm:ss’的日期展示在页面上.本来是自己写了个函数,但是奈何leader说我们项目用了moment了,你为什么不用 ...

  9. pl&sol;sql oracle数据库中文数据显示异常或者不能使用中文查询的解决办法

    1首先我们需要找到pl/sql developer 目录 然后在该目录下 创建一个bat文件 在文件中定义 set NLS_LANG=AMERICAN_AMERICA.UTF8start PLSQLD ...

  10. Nancy异步用法

    个人笔记,记录Nancy异步用法 基类,所有请求都将首先执行该类,并执行Before事件 namespace CxyAdvert.Base { public class BaseNancyModel ...