您的位置:首页 > 其它

HDU 4585 Shaolin (map)

2015-06-04 20:11 441 查看
题意:

思路:

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: