• 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
  • 相关阅读:
    安装浏览器的vue插件
    webpack学习笔记-2-file-loader 和 url-loader
    webpack4.x最详细入门讲解
    简单地使用webpack进行打包
    vue动态监听浏览器窗口高度
    Vue 中 export及export default的区别
    vue 路由懒加载 resolve vue-router配置
    javascript深入理解js闭包
    JS截取字符串常用方法详细整理
    糗事之 -- 用ssh公钥实现免密码登录
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4624861.html
Copyright © 2020-2023  润新知