首页 > 代码库 > C++ P2874 冷血格斗场

C++ P2874 冷血格斗场

#include<iostream>
#include<cstdio>
#include<map>
#include<cmath>
using namespace std;
const int MAXN=1000000000;
int n,power,id,x,idx;
map<int,int>member;
map<int,int>::iterator bt;
int main()
{
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    member[MAXN]=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&id,&power);
        bt=member.lower_bound(power);
        if(bt==member.end()) bt--;
        x=abs(power-bt->first);
        idx=bt->second;
        if(bt!=member.begin()){
            bt--;
            if(x>abs(power-bt->first)||x==abs(power-bt->first)&&bt->second<idx)
                idx=bt->second;
        }
        printf("%d %d\n",id,idx);
        bt=member.find(power);
        if(bt==member.end()||bt->second>id) member[power]=id;
    }
    return 0;
}

//注释过一段时间再来加上;

C++ P2874 冷血格斗场