码迷,mamicode.com
首页 > 其他好文 > 详细

[ABC160] 题解

时间:2020-03-28 23:38:59      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:cin   题解   for   lin   point   mes   pre   space   als   

由于是ABC, 所以ABC题过于简单就咕咕咕了

D Line++

枚举一下所有组判断一下即可

#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;
}

E Red and Green Apples

显然从小到大排好序后最优,无色的苹果不用管它,因为只要你取到个数且不超过限制一定可以通过分配使他满足。(所以代码特别好写)

#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;
}

F Distributing Integers

暂时咕咕咕

[ABC160] 题解

标签:cin   题解   for   lin   point   mes   pre   space   als   

原文地址:https://www.cnblogs.com/LJB00131/p/12590040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!