北理2017校赛 - A.速度牛排 - 贪心

1.题目描述:

A.速度牛排(红色)

成绩0开启时间2017年05月14日 Sunday 09:30
折扣0.8折扣时间2017年05月12日 Friday 19:50
允许迟交关闭时间2017年05月14日 Sunday 15:00

题目描述

食宝街有一家叫速度牛排的牛排店,lx很喜欢去那里吃饭。速度牛排有5种肉质选择,按价格从小到大排序依次为:M2M4M6M8M10

某一天lx和小伙伴一起去吃牛排,其中有n个人普通有钱,会选择价格不超过M6的牛排,有m个人超级有钱,对价格没有任何限制。

当天速度牛排有k份牛排,问最少还要做多少份牛排才能让lx和小伙伴们所有人都吃上牛排?

 

输入

第一行包含一个整数,表示用例组数。

每个用例第一行输入三个整数knm1<=k,n,m<=10,000),接下来包含k行,每行一个字符串表示是速度牛排中的哪种牛排。

 

输出

每个用例输出一个整数,表示最少还要做的牛排份数。

 

样例输入

1

6 4 2

M2

M4

M6

M8

M10

M8

 

样例输出

1


3.解题思路:

如果是2、4、6贪心地给普通人就好了

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int p[5];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	long _begin_time = clock();
#endif
	int t, n, m, k;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d%d", &k, &n, &m);
		for (int i = 0; i < k; i++)
		{
			char ch[4];
			scanf("%s", &ch);
			int x = ch[1] - '0';
			if (x == 2 || x == 4 || x == 6)
			{
				if (n > 0)
					n--;
				else if (m > 0)
					m--;
			}
			else if (m > 0)
				m--;
		}
		printf("%d\n", n + m);
	}
#ifndef ONLINE_JUDGE
	long _end_time = clock();
	printf("time = %ld ms.", _end_time - _begin_time);
#endif
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值