Untitled
unknown
plain_text
23 days ago
2.1 kB
2
Indexable
Never
#include <iostream> #include <vector> #include <set> using namespace std; struct Solider{ int id, score, team; Solider(int id, int score) { this->id = id; this->score = score; } }; Solider soliders[100001]; struct cmp{ bool operator()(Solider &a, Solider &b) { if(a.score == b.score) { return a.id > b.id; } return a.score > b.score; } }; set<Solider, cmp>team[6]; void init() { for(int i=1; i<=100000; i++) { soliders[i].id = 0; soliders[i].score = 0; } for(int i=1; i<=5; i++) { team[i].clear(); } } void hire(int mID, int mTeam, int mScore) { soliders[mID].score = mScore; soliders[mID].team = mTeam; Solider newMember = Solider(mID, mScore); team[mTeam].insert(newMember); } void fire(int mID) { int t = soliders[mID].team; soliders[mID].score = 0; soliders[mID].team = 0; for(auto &it: team[t]) { if(it.id == mID) { team[t].erase(it); } } } void updateSoldier(int mID, int mScore) { Solider newMember = Solider(mID, mScore); soliders[mID].score = mScore; int t = soliders[mID].team; for(auto &it: team[t]) { if(it.id == mID) { team[t].erase(it); team[t].insert(newMember); } } } void updateTeam(int mTeam, int mChangeScore) { for(auto &it : team[mTeam]) { if(it.score + mChangeScore > 5 ) { int id = it.id; Solider newMember = Solider(id, 5); team[mTeam].erase(it); team[mTeam].insert(newMember); soliders[id].score = 5; } else if(it.score + mChangeScore < 1) { int id = it.id; Solider newMember = Solider(id, 1); team[mTeam].erase(it); team[mTeam].insert(newMember); soliders[id].score = 1; } else { int id = it.id; int prevScore = it.score; Solider newMember = Solider(id, prevScore + mChangeScore); team[mTeam].erase(it); team[mTeam].insert(newMember); soliders[id].score = prevScore + mChangeScore; } } } int bestSoldier(int mTeam) { auto it = team[mTeam].begin(); auto res = *it; int id = res.id; return id; }
Leave a Comment