题意:双方各有n各人,每个人呢有一个技能值,每个人且只能出战一次,如果A的技能大于B的技能,A所在方得两分,A技能值等于B的话,给得一分,输了不得分,问A方最多能得多少分。
这题贪心思路很多,,,但是对的没几个,,,,wa了4发都没怎么wa明白。
对于A方的几个技能值X,,,先在B中找一个小于X的最大值,,,这种关系找完后,,,在找剩下中能打成平手的。。。
// #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <algorithm> #include <iomanip> #include <sstream> #include <string> #include <stack> #include <queue> #include <deque> #include <vector> #include <map> #include <set> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <limits.h> // #define DEBUG #ifdef DEBUG #define debug(...) printf( __VA_ARGS__ ) #else #define debug(...) #endif #define MEM(x,y) memset(x, y,sizeof x) using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> ii; const int inf = 1 << 30; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int n; int A[60], B[60]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int icase = 0, t; cin >> t; while(t--){ cin >> n; for (int i = 0;i < n;++i) cin >> A[i]; for (int i = 0;i < n;++i) cin >> B[i]; sort(A,A+n); sort(B,B+n); int sum = 0; for (int i = 0;i < n;++i){ int last = -1; for (int j = 0;j < n;++j){ if (B[j] == -1) continue; if (B[j] > A[i]) break; if (B[j] < A[i]) last = j; } if (last != -1){ A[i] = -1; sum += 2; B[last] = -1; } } for (int i = 0;i < n;++i){ if (A[i] == -1) continue; for (int j = 0;j < n;++j){ if (A[i] < B[j]) break; if (B[j] == -1) continue; if (A[i] == B[j]){ B[j] = -1; sum += 1; break; } } } printf("Case %d: %d\n", ++icase, sum); } return 0; }