您的位置:首页 > 其它

HDU 4585 Shaolin STL map 水

2014-06-24 09:10 253 查看
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<set>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;
#include<map>
map<int,int >m;
int main()
{
int n;
while(scanf("%d",&n),n){
int a,b;
int i;
m.clear();
m[1000000000]=1; // key值为1000000000  映射值:1;
for(i=0;i<n;i++){
scanf("%d%d",&a,&b);
printf("%d",a);
map<int,int>::iterator t=m.lower_bound(b);//寻找到 b<=最近
//			printf("%d %d\n",t->second,t->first);
//          t->second  表示映射值
//          t->first  表示key值
if(t==m.end())//b为最大
{
t--;
printf(" %d\n",t->second);
}
else
{
int t1 = t->first;
int tmp = t->second;
if(t!=m.begin())
{
t--;
if(b-t->first<=t1-b)// b在中间 比较两端 差值
printf(" %d\n",t->second);
else printf(" %d\n",tmp);

}
else printf(" %d\n",t->second);// b最小
}
m[b]=a;// 加入
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: