标签:cin 题解 for lin point mes pre space als
枚举一下所有组判断一下即可
#include<bits/stdc++.h>
using namespace std;
int n, x, y, ans[10005];
int main()
{
cin >> n >> x >> y;
for(int i = 1; i <= n; i++)
{
for(int j = i + 1; j <= n; j++)
{
int t = min(min(j - i, abs(x - i) + abs(j - x)), min(abs(y - i) + abs(j - y), abs(x - i) + 1 + abs(j - y)));
ans[t]++;
}
}
for(int i = 1; i <= n - 1; i++)
printf("%d\n", ans[i]);
return 0;
}
显然从小到大排好序后最优,无色的苹果不用管它,因为只要你取到个数且不超过限制一定可以通过分配使他满足。(所以代码特别好写)
#include<bits/stdc++.h>
using namespace std;
#define N 500005
int a, b, c, n, X, Y;
long long ans = 0;
struct point
{
int v, id;
bool operator < (const point &o) const
{
return v > o.v;
}
}p[N];
int main()
{
ios::sync_with_stdio(false);
cin >> X >> Y >> a >> b >> c;
n = a + b + c;
for(int i = 1; i <= n; i++)
{
cin >> p[i].v;
if(i <= a) p[i].id = 1;
else if(i <= a + b) p[i].id = 2;
else p[i].id = 3;
}
sort(p + 1, p + n + 1);
int x = 0, y = 0, cnt = 0;
for(int i = 1; i <= n; i++)
{
if(p[i].id == 1)
{
if(x == X) continue;
else x++;
}
else if(p[i].id == 2)
{
if(y == Y) continue;
else y++;
}
ans += 1ll * p[i].v;
cnt++;
if(cnt == X + Y) break;
}
cout << ans << endl;
return 0;
}
暂时咕咕咕
标签:cin 题解 for lin point mes pre space als
原文地址:https://www.cnblogs.com/LJB00131/p/12590040.html