HDU 4585 Shaolin(水题,STL)
Shaolin
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 64 Accepted Submission(s): 38
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.
In each test case:
The first line is a integer n (0 <n <=100,000),meaning the number of monks who joined Shaolin after the master did.(The master is not included).Then n lines follow. Each line has two integer k and g, meaning a monk's id and his fighting grade.( 0<= k ,g<=5,000,000)
The monks are listed by ascending order of jointing time.In other words, monks who joined Shaolin earlier come first.
The input ends with n = 0.
2 1
3 3
4 2
0
3 2
4 2
/* **********************************************
Author : kuangbin
Created Time: 2013/8/10 11:55:20
File Name : F:\2013ACM练习\比赛练习\2013杭州邀请赛重现\1011.cpp
*********************************************** */ #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()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
set<int>st;
map<int,int>mp;
int n;
while(scanf("%d",&n) == && n)
{
st.clear();
mp.clear();
st.insert();
mp[] = ;
int u,v;
while(n--)
{
scanf("%d%d",&u,&v);
printf("%d ",u);
set<int>::iterator it = st.lower_bound(v);
if(it == st.end())
{
it--;
printf("%d\n",mp[*it]);
}
else
{
int t1 = (*it);
if(it != st.begin())
{
it--;
if(v - (*it) <= t1 - v)
{
printf("%d\n",mp[*it]);
}
else printf("%d\n",mp[t1]);
}
else printf("%d\n",mp[*it]);
}
mp[v] = u;
st.insert(v);
}
}
return ;
}
今天才知道原来直接用map也可以实现。
原来map也是排序了的,Orz....
/* **********************************************
Author : kuangbin
Created Time: 2013/8/10 11:55:20
File Name : F:\2013ACM练习\比赛练习\2013杭州邀请赛重现\1011.cpp
*********************************************** */ #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()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
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 ;
}
HDU 4585 Shaolin(水题,STL)的更多相关文章
- HDU 4585 Shaolin(STL map)
Shaolin Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit cid= ...
- HDU 4585 Shaolin(Treap找前驱和后继)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Su ...
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 4585 Shaolin (STL map)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- hdu 4585 Shaolin(STL map)
Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...
- HDU 4585 Shaolin (STL)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- HDU 4585 Shaolin (STL)
没想到map还有排序功能,默认按照键值从小到大排序 #include <cstdio> #include <iostream> #include <cstring> ...
随机推荐
- 基于scrapy的分布式爬虫抓取新浪微博个人信息和微博内容存入MySQL
为了学习机器学习深度学习和文本挖掘方面的知识,需要获取一定的数据,新浪微博的大量数据可以作为此次研究历程的对象 一.环境准备 python 2.7 scrapy框架的部署(可以查看上一篇博客的简 ...
- iOS通知中心
iOS通知中心 它是iOS程序内部的一种消息广播机制,通过它,可以实现无引用关系的对象之间的通信.通知中心他是基于观察者模式,它只能进行程序内部通信,不能跨应用程序进程通信. 当通知中心接受到消息后会 ...
- ubuntu上安装MySQL详解
1. 安装 在终端输入 sudo apt-get install mysql-server mysql-client 回车 2.安装完成后检测MySQL的状态 systemctl status my ...
- 关于OnPaint、FormPaint会不停的触发 触发多次的情形---讨论总结
关于OnPaint会不停的一直触发 触发多次的问题,是这样的 首先OnPaint是响应windows的WM_PAINT消息的,你显示器上 能看到的比如说 按钮button, memo什么的 都是画出来 ...
- LightOJ - 1010 Knights in Chessboard(规律)
题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...
- HDU 2822
Dogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Spring学习-理解IOC和依赖注入
最近刚买了一本介绍ssm框架的书,里面主要对Mybatis.spring.springmvc和redis做了很多的讲解,个人觉得虽然有的内容我看不懂,但是整体上还是不错的.最近正在学习中,一边学习一边 ...
- Download failed : Oracle JDK 7 is NOT installed,解决oracle jdk7的问题
先了解下概念: jdk(java development kit),就是java的开发工具集,顾名思义就是做开发用的,其中包括javac,也就是java compiler等.jre(java runt ...
- python lxml教程
目前有很多xml,html文档的parser,如标准库的xml.etree , beautifulsoup , 还有lxml. 都用下来感觉lxml不错,速度也还行,就他了. 围绕三个问题: 问题 ...
- 如何使用Inno Setup Compiler制作安装软件包
工具/原料 Inno Setup Compiler汉化版软件 方法/步骤 启动Inno Setup Compiler汉化版软件. 选择创建新的空白脚本文件,按确定. 然后按下一步. ...