Boats Competition solution
题意:
暴力枚举
#include <iostream> #include<algorithm> #include<cstring> using namespace std; int a[55], ans, mc[105]; bool vis[55]; int main() { int t; cin >> t; while(t--) { int n; cin >> n; ans = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n +1); for(int w = 1; w <= a[n] + a[n - 1]; w++) { int ant = 0; memset(mc, 0, sizeof(mc)); for(int i = 1; i <= n; i++) { mc[a[i]]++; } for(int i = 1; i <= n; i++) { if(w - a[i] >= 1 && mc[w - a[i]] && mc[a[i]]) { if(w - a[i] == a[i] && mc[w - a[i]] <= 1) continue; cnt++; mc[w - a[i]]--; mc[a[i]]--; } } ans = max(ans, ant); } cout << ans << endl; } return 0; }