12626 - I ❤ Pizza

 G- I ❤ Pizza 

Context

Everybody loves pizza: Margarita, Four cheese, Salami,Caprichosa, Neapolitan, Hawaiian... The famous pizza Margarita is namedafter the Italian Queen Margarita of Savoy. It is said that the chefRaffaele Esposito gave her to choose from a variety of pizzas he hadprepared specially for the Queen. Margarita chose this pizza in honorof the colors of the Italian flag: red tomato, white cheese, and greenbasil.

Una rica pizza

However, some people argue that, in fact, Queen Margarita didnot like onion, and as all the other pizzas had onion, she had nochoice but that pizza.

TheProblem

In our particular computerized kitchen, ingredients are named bycapital letters: A, B, C, D... Thus, to make a pizza MARGARITA we needas many ingredients as their letters, i.e. one M, three A, two R, oneG, one I, and one T.

For example, if we have the ingredients:

AAAAAAMMRRTITIGGRRRRRRRR

Then we can make 2 pizzas MARGARITA, and still spare some R.

Given a set of ingredients, you have to say how many pizzasMARGARITA can be made. Note that there may be leftover ingredients, andalso there may be unnecessary ingredients, such as B.

TheInput

The first line contains a natural number, N, which indicatesthe number of test cases.

Each test case is given in one line. This line contains aseries of capital letters from A to Z, which can be messy and may berepeated. At most one line can have 600 characters.

TheOutput

For each test case, you must indicate how many pizzasMARGARITA can be made with the letters available, taking into accountthat there may be spare letters.

SampleInput

5
MARGARITA
AAAAAAMMRRTITIGGRRRRRRRR
AMARGITA
BOLOGNESACAPRICHOSATOMATERA
ABCDEFGHIJKLMNOPQRSTUVWXYZ

SampleOutput

1
2
0
1
0
#include<stdio.h>
#include<string.h>
int min(int *a)
{
	int i,min=a[0];
	for(i=0;i<6;i++)
		if(a[i]<min)
			min=a[i];
	return min;
}
int main()
{
	int n,i;
	char b[605];
	scanf("%d",&n);
	while(n--)
	{
		int a[6]={0};
		scanf("%s",b);
		for(i=0;i<strlen(b);i++)
		{
			if(b[i]=='M') a[0]++;
			if(b[i]=='A') a[1]++;
			if(b[i]=='R') a[2]++;
			if(b[i]=='G') a[3]++;
			if(b[i]=='I') a[4]++;
			if(b[i]=='T') a[5]++;
		}
		a[1]/=3; a[2]/=2;
		printf("%d\n",min(a));
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分披萨 题目描述 在给定 m个人的情况下,有 n块比萨。每块比萨都有一个分数。我们希望将比萨分配给每个人,使得每个人得分尽可能多。分数可以为 0。 例如,在给定 3 个人和 3 块比萨的情况下,比萨的得分分别为 5, 4, 7,我们可以将比萨分配为: (5)、(4)、(7),以便每个人分别得到 5, 4, 7 分。 给定 m 个人和 n 块比萨,每块比萨的得分以及每个人对比萨的偏好 (可能有中性,喜欢或者讨厌),你的任务是计算每个人得到的最大分数。 输入格式 输入包含多组测试数据。 每组测试数据的第一行包含两个整数 n(1≤n≤1000) 和 m(1≤m≤100) — 分别表示比萨的数量和人数。第二行包含 n 个整数 a1,a2…an(1≤ai≤1000) — 表示每块比萨的分数。接下来的 m 行每行包含 n 个整数 b1,b2…bn(−1≤bi≤1) — 表示每个人喜欢(1),中性(0)或者讨厌(−1)每块比萨。 输入保证对于每组测试数据至少存在一个人喜欢比萨。 当 n = m = 0 时,表示输入结束。 输出格式 对于每组测试数据,输出 m 行。每行包含一个整数,表示每个人得到的最大分数。 样例输入 3 3 5 4 7 1 0 -1 0 1 0 1 0 0 3 3 4 7 8 -1 0 1 1 -1 0 1 0 0 样例输出 5 4 7 4 7 8 ```python # 代码: while True: n, m = list(map(int, input().split())) if n == 0 and m == 0: break pizzas = list(map(int, input().split())) preferences = [list(map(int, input().split())) for _ in range(m)] scores = [0] * m for i in range(n): max_score = 0 for j in range(m): if preferences[j][i] == 1: max_score = max(max_score, pizzas[i]) elif preferences[j][i] == 0: max_score = max(max_score, pizzas[i] // 2) for j in range(m): if preferences[j][i] == 1 or (preferences[j][i] == 0 and max_score == pizzas[i] // 2): scores[j] += max_score for score in scores: print(score) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值