第一题 a和b部门打乒乓球 全ac
#include<iostream> #include<vector> using namespace std; int main(){ int times; cin >> times; while(times > 0){ int ans = 0; vector<vector<int> > sl(4); //0 1 是a组男和女的实力,23是b组男和女的实力 for(int i = 0;i < 4; ++i){ for(int j = 0;j < 3;j++){ int n; cin >> n; sl[i].push_back(n); } } for(int am = 0;am < 3;am++) for(int aw = 0;aw < 3;aw++) for(int bm = 0;bm < 3;bm++) for(int bw = 0;bw < 3;bw++){ int wins = 0; if( (sl[2][bm] + sl[3][bw]) > (sl[0][am] + sl[1][aw])){ wins++; } if( (sl[2][(bm + 1) % 3] + sl[2][(bm + 2) % 3]) > (sl[0][(am + 1) % 3] + sl[0][(am + 2) % 3])){ wins++; } if( (sl[3][(bw+ 1) % 3] + sl[3][(bw + 2) % 3]) > (sl[1][(aw + 1) % 3] + sl[1][(aw + 2) % 3]) ){ wins++; } if(wins >= 2){ ans++; } } cout << ans << endl; times--; } return 0; }
#include<string> #include<iostream> #include<algorithm> #include<vector> using namespace std; int game(char c1, char c2){ if(c1 == 'R'){ if(c2 == 'R'){ return 0; }else if(c2 == 'S'){ return 1; }else{ return 2; } }else if(c1 == 'S'){ if(c2 == 'R'){ return 2; }else if(c2 == 'S'){ return 0; }else{ return 1; } }else if(c1 == 'C'){ if(c2 == 'R'){ return 1; }else if(c2 == 'S'){ return 2; }else{ return 0; } } } int play(int p1, int p2, int num, int rounds, string kid){ while(rounds > 0){ if(game(kid[p1], kid[p2]) == 0){ // cout << "round: " << rounds << " no" << " win" << endl; p1 = (p1 + 1) % num; p2 = (p2 + 1) % num; }else if(game(kid[p1], kid[p2]) == 1){ // cout << "round: " << rounds << " "<< "kid" << p1 << ": " << kid[p1] << " win" << endl; kid.erase(p2, 1); num--; if(num < 2){ return num; } if(p2 >= num){ p2 %= num; } if(p1 >= num){ p1--; } }else if(game(kid[p1], kid[p2]) == 2){ // cout << "round: " << rounds << " "<< "kid" << p2 << ": " << kid[p2] << " win" << endl; kid.erase(p1, 1); num--; if(num < 2){ return num; } if(p2 >= num){ p2 %= num; } if(p1 >= num){ p2++; p1 %= num; } } rounds--; } return num; } int main(){ int times; cin >> times; while(times > 0){ vector<int> ans; int num, rounds; string kid; cin >> num >> rounds; cin >> kid; if(num == 1){ cout << 1; }else{ for(int i = 0;i < num; ++i){ int j = (i + 1) % num; ans.push_back(play(i, j, num, rounds, kid)); } sort(ans.begin(), ans.end()); cout << ans[ans.size() - 1] << endl; } times--; } return 0; }
第三题 排行榜 ,中位数奖励 ac 60%
#include<vector> #include<iostream> #include<unordered_set> #include<unordered_map> using namespace std; void myinsert(vector<int> &phb, int n){ auto it = phb.begin(); for(it; it != phb.end(); ++ it){ if(*it >= n){ phb.emplace(it, n); break; } } if(it == phb.end()){ phb.push_back(n); } } int main(){ int T; cin >> T; while(T > 0){ unordered_set<int> oldrev; unordered_map<int, int> itn; vector<int> phb; int ans = 0; int times; cin >> times; while(times > 0){ int id, num; cin >> id >> num; if(itn.find(id) != itn.end()){ if(num > itn[id]){ for(auto it = phb.begin(); it != phb.end(); it++){ if(*it == itn[id]){ phb.erase(it); break; } } myinsert(phb, num); itn[id] = num; if(oldrev.find(id) == oldrev.end()){ int mid; if(phb.size() % 2 == 1){ mid = phb[phb.size() / 2]; }else{ mid = (phb[phb.size() / 2 - 1] + phb[phb.size() / 2]) / 2; } if(mid == num){ ans++; oldrev.emplace(id); } } } }else{ myinsert(phb, num); itn[id] = num; int mid; if(phb.size() % 2 == 1){ mid = phb[phb.size() / 2]; }else{ mid = (phb[phb.size() / 2 - 1] + phb[phb.size() / 2]) / 2; } if(mid == num){ ans++; oldrev.emplace(id); } } times--; } cout << ans << endl; T--; } }
第三题只ac 60% 想不明白为什么qwq
全部评论
(3) 回帖