HDU 4585
http://acm.hdu.edu.cn/showproblem.php?pid=4585
从原来的人中找出战斗数值最接近的,输出他们两人的序号
要在logn的复杂度完成查找,我用的是set,当然用map也可以,两个内部都是红黑树实现
水题一道
#include <iostream>
#include <cstdio>
#include <set>
#include <cmath>
using namespace std ;
struct node
{
int id,lv ;
friend bool operator <(node a,node b)//按lv从小到大排序
{
return a.lv>b.lv;
}
} ;
int main()
{
int n ;
set <node> S ;
while(~scanf("%d",&n),n)
{
S.clear() ;
node ma ;
ma.id= ;ma.lv= ;
S.insert(ma) ;
while(n--)
{
scanf("%d%d",&ma.id,&ma.lv) ;
set <node>::iterator it,it1 ;
it=S.lower_bound(ma) ;
if(it==S.begin())
{
printf("%d %d\n",ma.id,it->id) ;
}
else
{
it1=it ;
it-- ;
if(fabs(it1->lv-ma.lv)>fabs(it->lv-ma.lv))
{
printf("%d %d\n",ma.id,it->id) ;
}
else
{
printf("%d %d\n",ma.id,it1->id) ;
}
}
S.insert(ma) ;
}
}
return ;
}
HDU 4585的更多相关文章
- HDU 4585 Shaolin(Treap找前驱和后继)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Su ...
- HDU 4585 Shaolin(STL map)
Shaolin Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit cid= ...
- [HDU 4585] Shaolin (map应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585 题目大意:不停的插入数字,问你跟他相距近的ID号.如果有两个距离相近的话选择小的那个. 用map ...
- hdu 4585 Shaolin treap
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Problem ...
- A -- HDU 4585 Shaolin
Shaolin Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java clas ...
- hdu 4585 map **
题意: Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every ...
- hdu 4585 Shaolin
原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46093 #include<algorithm> #in ...
- hdu 4585 set应用
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #i ...
- 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 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- Ubuntu 14.04设置开机启动脚本的方法
rc.local脚本 rc.local脚本是一个ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/etc/路径下,需要root权限才能修改. 该脚本具体格式如下: #! ...
- ubuntu , 安装包的具体文件的查看方法
To see all the files the package installed onto your system, do this: dpkg-query -L <package_name ...
- 通过修改manifest文件来解决Vista/Win7/Win8/win10下应用程序兼容性问题
https://www.cnblogs.com/snowbook/p/5363990.html
- spoj The Next Palindrome
题意:比给出的数大的最小回文数. 先用前n/2长对称到后面,如果没变大,在中间加1,进位,再对称. //#pragma comment(linker,"/STACK:1024000000,1 ...
- Confluence 6 的 Crowd 权限
只读(Read Only) 从 Crowd 上获取的用户,用户组和用户组成员信息只具有读取权限,你只能在 Crowd 上对你的配置进行修改.你不能通过你的应用程序管理员界面修改,用户,用户组,用足成员 ...
- 『PyTorch』第二弹重置_Tensor对象
『PyTorch』第二弹_张量 Tensor基础操作 简单的初始化 import torch as t Tensor基础操作 # 构建张量空间,不初始化 x = t.Tensor(5,3) x -2. ...
- 51nod-1534-博弈
1534 棋子游戏 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 波雷卡普和瓦西里喜欢简单的逻辑游戏.今天他们 ...
- 双机热备(准)-->RAC(夭折)-->DG(异地容灾)
以下有的地方为oracle专业术语,非懂勿喷.前段时间某项目负责人告知,他们应用需要一套oracle数据库环境运行模式为双机热备.简单了解下对于现在已经非常成熟的RAC再合适不过了.详细问了问当前服务 ...
- turbine源码分析
turbine源码分析 1.turbine架构设计 一切从InstanceDiscovery模块开始,该模块提供所有的主机信息.它会定期的发送更新,ConnectionManager负责创建连接到主机 ...