zoukankan      html  css  js  c++  java
  • hdu 4585 map **

    题意:

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

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <queue>
     7 #include <set>
     8 #include <map>
     9 #include <string>
    10 #include <math.h>
    11 #include <stdlib.h>
    12 using namespace std;
    13 
    14 int main()
    15 {
    16     map<int,int>mp;
    17     int n;
    18     while(scanf("%d",&n) == 1 && n)
    19     {
    20         mp.clear();
    21         mp[1000000000] = 1;
    22         int u,v;
    23         while(n--)
    24         {
    25             scanf("%d%d",&u,&v);
    26             printf("%d ",u);
    27             map<int,int>::iterator it = mp.lower_bound(v);
    28             if(it == mp.end())
    29             {
    30                 it--;
    31                 printf("%d
    ",it->second);
    32             }
    33             else
    34             {
    35                 int t1 = it->first;
    36                 int tmp = it->second;
    37                 if(it != mp.begin())
    38                 {
    39                     it--;
    40                     if(v - it->first <= t1 - v)
    41                     {
    42                         printf("%d
    ",it->second);
    43                     }
    44                     else printf("%d
    ",tmp);
    45                 }
    46                 else printf("%d
    ",it->second);
    47             }
    48             mp[v] = u;
    49         }
    50     }
    51     return 0;
    52 }
    2015/7/6
  • 相关阅读:
    HBase- 安装单机版HBase
    javascript中的设计模式之模板方法模式
    win 设置自动启动软件
    php高精度加减乘除
    frp实现内网穿透,实现夸服务器访问
    OCM 12c 直考预备知识点
    Oracle 19c New Features : Active Data Guard DML Redirect
    3级搭建类302-Oracle 19c RAC 双节点搭建
    VMWare WorkStation 15.5 配置RAC共享存储节点二无法识别共享磁盘UUID解决办法
    你还在争论 count(*) 与 count(column) 哪个更快?
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4624861.html
Copyright © 2011-2022 走看看