注意
1.相同金牌数,相同名次,其他类似。
2.存在人数或者奖牌为0的情况。
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
#include <unordered_map>
#include <map>
#include <cfloat>
using namespace std;
typedef pair<int, int> PII;
const int N = 245;
struct country{
int g, m, pg, pm, ind, rank; //四种排名
}E[N];
bool cmp1(PII a, PII b){
return a.first > b.first;
}
bool cmp2(pair<double, int> a, pair<double, int> b){
return a.first > b.first;
}
vector<PII> go, me;
vector<pair<double, int>> peg, pem;
int main(){
int n, m, Gold, Medal, People;
while(cin>>n>>m){
go.clear();
me.clear();
peg.clear();
pem.clear();
for(int i = 0; i < n; i++){
cin>>Gold>>Medal>>People;
go.push_back({Gold, i});
me.push_back({Medal, i});
double t, tt;
if(Gold==0 && People==0){ //金牌和人数都为0时 结果为0
t = 0;
}else if(People==0 && Gold!=0){ //金牌数不为0 人数为0时 结果为无穷大
t = FLT_MAX;
}else
t = Gold*1.0/People;
if(Medal==0 && People==0){
tt = 0;
}else if(People==0 && Medal!=0){
tt = FLT_MAX;
}else
tt = Medal*1.0/People;
peg.push_back({t, i});
pem.push_back({tt, i});
}
sort(go.begin(), go.end(), cmp1);
sort(me.begin(), me.end(), cmp1);
sort(peg.begin(), peg.end(), cmp2);
sort(pem.begin(), pem.end(), cmp2);
for(int i = 0; i < n; i++){ //具有相同成果的 处于同一排名
//金牌
int ida = go[i].second;
if(i == 0 || go[i-1].first != go[i].first){
E[ida].g = i + 1;
}else E[ida].g = E[go[i-1].second].g;
//奖牌
int idb = me[i].second;
if(i == 0 || me[i-1].first != me[i].first){
E[idb].m = i + 1;
}else E[idb].m = E[me[i-1].second].m;
//人均金牌
int idc = peg[i].second;
if(i == 0 || peg[i-1].first != peg[i].first){
E[idc].pg = i + 1;
}else E[idc].pg = E[peg[i-1].second].pg;
//人均奖牌
int idd = pem[i].second;
if(i == 0 || pem[i-1].first != pem[i].first){
E[idd].pm = i + 1;
}else E[idd].pm = E[pem[i-1].second].pm;
}
for(int i = 0; i < n; i++){
E[i].rank = 300;
if(E[i].g < E[i].rank){
E[i].rank = E[i].g;
E[i].ind = 1;
}
if(E[i].m < E[i].rank){
E[i].rank = E[i].m;
E[i].ind = 2;
}
if(E[i].pg < E[i].rank){
E[i].rank = E[i].pg;
E[i].ind = 3;
}
if(E[i].pm < E[i].rank){
E[i].rank = E[i].pm;
E[i].ind = 4;
}
}
int x;
for(int i = 0; i < m; i++){
cin>>x;
cout<<E[x].rank<<":"<<E[x].ind<<endl;
}
cout<<endl;
}
return 0;
}