042 热血格斗场

#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include <map>

using namespace std;

int main() {
	typedef map<int, int,less<int>> intmap;
	intmap mmp;
	mmp.insert(intmap::value_type(1000000000, 1));
	int rs;
	cin >> rs;
	stringstream res;
	for (int i = 0;i < rs;++i) {
		int id, sorce;
		cin >> id >> sorce;
		if (mmp.size() == 1) {
			res << id << " " << 1 << endl;
			mmp.insert(make_pair(sorce, id));
		}
		else {
			pair < intmap::iterator, bool> pp = mmp.insert(make_pair(sorce, id));
			intmap::iterator aa(pp.first);
			bool bb(pp.second);
			//cout << (--aa)->second << "   " << (pp.first)->second << "   "<<(++pp.first)->second << endl;
			if (bb) {
				if ((sorce - ((--aa)->first)) <= (((++pp.first)->first) - sorce)) {
					res << id << " " << aa->second << endl;
				}
				else {
					res << id << " " << ((pp.first)->second) << endl;
				}
			}
		}
		
	}
	cout << res.str();


	for (intmap::iterator ii = mmp.begin(); ii != mmp.end();++ii) {
		cout << "(" << ii->first << "," << ii->second << ")";
	}

	return 0;
}

posted @ 2022-03-01 17:57  icefield817  阅读(61)  评论(0编辑  收藏  举报