拿物品
拿物品
http://www.nowcoder.com/questionTerminal/868cfb40d17344c89db303f9992fbf85
拿物品
https://ac.nowcoder.com/acm/contest/3003/F
本题实际考虑贪心
对于任意一个物品,倘若牛牛拿了,则牛牛得到ai,牛可乐失去bi,差值为ai+bi
故而每次牛牛和牛可乐都会选择 ai+bi当前最大的
#pragma warning (disable :4996) #include <iostream> #include <cstdio> #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; int n; pair<ll, ll>a[maxn], b[maxn]; pair<ll, ll>Sort[maxn]; int A[maxn], B[maxn]; int cmp(pair<ll,ll> a, pair<ll,ll> b) { if (a.first > b.first) { return 1; } pair<ll, ll>c; c = a; a = b; b = c; return 0; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i].first); a[i].second = i; } for (int j = 1; j <= n; j++) { scanf("%lld", &b[j].first); b[j].second = j; } for (int i = 1; i <= n; i++) { Sort[i].first = a[i].first + b[i].first; Sort[i].second= i; } sort(Sort + 1, Sort + n + 1, cmp); int ans = 0, cnt = 0; for (int i = 1; i <= n; i++) { A[ans++] = Sort[i].second; i++; if (i > n) break; B[cnt++] = Sort[i].second; } for (int i = 0; i < ans-1; i++) cout << A[i] << " "; cout <<A[ans-1]<< endl; for (int i = 0; i < cnt-1; i++) cout << B[i] << " "; cout <<B[cnt-1]<< endl; }