标签:air return com char word name print turn space
using namespace std;
#include<iostream>
#include<map>
#include<vector>
#include<fstream>
int abs(int a)
{
return a > 0 ? a : -a;
}
map<int, int> a;
void findafter(vector<pair<int,int>>&b, map<int, int>::iterator p,int temp,int strength){
while ((p != a.end()) && (abs(p->first - strength) == temp))
{
b.push_back(*p); p++;
}}
void findbefore(vector<pair<int, int>>&b, map<int, int>::iterator p1, int temp, int strength)
{
while ((p1 != a.begin()) && (abs(strength - p1->first) == temp))
{
b.push_back(*p1); p1--;
}
if (p1 == a.begin() && (abs(strength - p1->first) == temp))
b.push_back(*p1);
}
void fight(int id, int strength) {
int id1 = 100000000;
map<int, int>::iterator p = a.lower_bound(strength);
if (p == a.begin())//所有老会员实力都大于新会员
{
vector<pair<int, int>> b; int temp = (p->first - strength);
findafter(b, p, temp, strength);
for (auto e : b)
{
if (e.second < id1)
id1 = e.second;
}
}
else {
map<int, int>::iterator p1 = --p;
p++;
if (p == a.end())
{
vector<pair<int, int>> c;
int temp =abs( strength - p1->first);
findbefore(c, p1, temp, strength);
for (auto e : c)
{
if (e.second < id1)
id1 = e