首页 > 其他 > 详细

HDU 4585 Shaolin (map)

时间:2015-06-04 21:01:40      阅读:224      评论:0      收藏:0      [点我收藏+]

题意:

思路:

 

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
map<int,int> a;
const int INF=1000000000;
int main()
{
    int n;
    while(scanf("%d",&n) && n)
    {
        a.clear();
        a[INF]=1;
        for(int i=0;i<n;i++)
        {
            int id,x;
            scanf("%d %d",&id,&x);

            printf("%d ",id);
            map<int,int>::iterator index=a.lower_bound(x);
            int res1=index->first;
            int res2=index->second;
            if(index!=a.begin())
            {
                index--;
                if(x-index->first <= res1-x)
                    printf("%d\n",index->second);
                else
                    printf("%d\n",res2);
            }
            else
                printf("%d\n",res2);
            
            a[x]=id;
        }
    }
    return 0;
}

 

HDU 4585 Shaolin (map)

原文:http://www.cnblogs.com/sola1994/p/4552854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!