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的更多相关文章

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

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

  2. HDU 4585 Shaolin(STL map)

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

  3. [HDU 4585] Shaolin (map应用)

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

  4. hdu 4585 Shaolin treap

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

  5. A -- HDU 4585 Shaolin

    Shaolin Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d , %I64u Java clas ...

  6. hdu 4585 map **

    题意: Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shaolin temple every ...

  7. hdu 4585 Shaolin

    原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46093 #include<algorithm> #in ...

  8. hdu 4585 set应用

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #i ...

  9. hdu 4585 Shaolin(STL map)

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

随机推荐

  1. codevs 1200 同余方程 逆元

    题目描述 Description 求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入描述 Input Description 输入只有一行,包含两个正整数 a, b,用 一个 空 ...

  2. Spring 注解 @Resource和@Autowired

    @Resource和@Autowired两者都是做bean的注入使用. 其实@Resource并不是Spring的注解,他的包是javax.annotation.Resource 需要导入.但是Spr ...

  3. 雷林鹏分享:C# 索引器(Indexer)

    C# 索引器(Indexer) 索引器(Indexer) 允许一个对象可以像数组一样被索引.当您为类定义一个索引器时,该类的行为就会像一个 虚拟数组(virtual array) 一样.您可以使用数组 ...

  4. python模块——random模块(简单验证码实现)

    实现一个简单的验证码生成器 #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" # Usage: 验证 ...

  5. Serega and Fun CodeForces - 455D (分块 或 splay)

    大意:给定n元素序列, 2种操作 将区间$[l,r]$循环右移1位 询问$[l,r]$中有多少个等于k的元素 现在给定q个操作, 输出操作2的询问结果, 强制在线 思路1: 分块 每个块内维护一个链表 ...

  6. 『PyTorch』第五弹_深入理解Tensor对象_中上:索引

    一.普通索引 示例 a = t.Tensor(4,5) print(a) print(a[0:1,:2]) print(a[0,:2]) # 注意和前一种索引出来的值相同,shape不同 print( ...

  7. H.Playing games

    fwt #include<bits/stdc++.h> using namespace std; const int N=1<<19; const int mod=100000 ...

  8. Java容器——Map接口

    1.定义 Map用于保存存在映射关系<key, value>的数据.其中key值不能重复(使用equals()方法比较),value值可以重复. 2.常用实现类 HashMap:和Hash ...

  9. win10解除密码

  10. ECC算法整理纪要

    初始ECC算法 1.用户A 密钥生成 (1):用随机数发生器产生随机数k∈[1,n-1]: (2):计算椭圆曲线点PA=[k]G,为公钥,k为用户A私钥: 2. 用户B加密算法及流程 设需要发送的消息 ...