地址 https://algospot.com/judge/problem/read/MATCHORDER
解法就是 田忌赛马
当能战胜对手的时候使用最低成本 也就是刚好大于等于对手的最小分数
如果不能胜利 则选择 最低分数
代码如下
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int MAX_N = 150; vector<int> ruScore; vector<int> koScore; int n, m; void solve() { sort(koScore.begin(), koScore.end()); int total = m; int start = 0; int winCount = 0; for (int i = 0; i < m; i++) { int score = ruScore[i]; auto it = lower_bound(koScore.begin(), koScore.begin() + total, score); if (it == koScore.end()) { //没有找到大于等于的 填充一个最小的去匹配 koScore.erase(koScore.begin()); total--; } else { koScore.erase(it); winCount++; total--; } } cout << winCount << endl; } int main() { cin >> n; while (n--) { cin >> m; ruScore.clear(); koScore.clear(); for (int i = 0; i < m; i++) { int t; cin >> t; ruScore.push_back(t); } for (int i = 0; i < m; i++) { int t; cin >> t; koScore.push_back(t); } solve(); } return 0; }