The 2017 ACM-ICPC Asia East Continent League Final——M-World Cup

本文介绍了一道关于2018年世界杯购票的算法题,涉及比赛流程、票价和预算计算。题目要求根据输入的票价和购买的票数,计算出用于购票的每日预算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                        M - World Cup

The 2018 World Cup will be hosted in Russia. 32 national teams will be divided into 8 groups. Each group consists of 4 teams. In group matches, each pair (unordered) of teams in the group will have a match. Top 2 teams with the highest score in each group will advance to eighth-finals. Winners of each eighth-final will advance to quarter-finals. Then, the winners of each quarter-final will advance to semi-finals. Eventually, the World Champion will be the winner of the World Final which is played between the two winners of the semi-finals.

Each match is labeled with a match ID sequenced from 1 to 63, with group matches followed by eighth-final matches followed by quarter-final matches followed by semi-finals matches and finally the final match.

Zhuojie is going to watch the 2018 World Cup. Since the World Champion of ACM-ICPC is very rich, he decides to spend 0.01% of his daily salary to buy tickets. However, there are only match IDs on the tickets and the prices are missing. Can you calculate how much Google pays Zhuojie every workday? Note that Zhuojie can buy multiple tickets for one match.

Input

The input starts with one line containing exactly one integer T, the number of test cases.

Each test case contains 3 lines. The first line contains 5 integers, indicating the ticket price for group match, eighth-final match, quarter-final match, semi-final match and the final match. The second line contains one integer N, the number of tickets Zhuojie buys. The third line contains N integers, each indicating the match ID on the ticket.

  • 1 ≤ T ≤ 100.
  • 1 ≤ N ≤ 105.

Output

For each test case, output one line containing "Case #x: y" where x is the test case number (starting from 1) and y is daily salary of Zhuojie.

Example

Input

1
11 12 13 14 15
2
1 49

Output

Case #1: 230000

题意描述:

已知世界杯比赛中32支队伍共要进行63场比赛,其中32进16为晋级赛,32支队伍分为8个小组,每个小组4支队伍;一组里的每两支队伍都要进行一场比赛;小组中的前两名晋级16强。而剩余16强进8强、8进4、半决赛和决赛都为淘汰赛。即随机分配两支队伍,胜者晋级,败者淘汰。每组样例有三行,第一行为五种比赛的门票价格,第二行为想要观看的比赛的总场次数,第三行为想要观看的比赛场次。求观看比赛需要花费多少钱。

解题思路:

有题意可知,1-48场为32进16的晋级赛,49-56场为16进8的淘汰赛,57-60场为8进4的淘汰赛,61-62场为4进2的半决赛,63场为决赛。将五种比赛的价格存储到数组中,输入观看场次,累加上该场次的对应价格。最后输出总价格,为防止数据溢出,可直接在输出数后加4个0,不需要乘上10000。

程序代码:

#include<stdio.h>
int main()
{
	int t,m,i,j,n,a[10],sum;
	scanf("%d",&t);
	j=1;
	while(t--)
	{
		for(i=1;i<=5;i++)
			scanf("%d",&a[i]);
		scanf("%d",&n);
		sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&m);
			if(m>=1&&m<=48)
				sum+=a[1];
			if(m>=49&&m<=56)
				sum+=a[2];
			if(m>=57&&m<=60)
				sum+=a[3];
			if(m>=61&&m<=62)
				sum+=a[4];
			if(m==63)
				sum+=a[5];
		}
		printf("Case #%d: %d0000\n",j,sum);
		j++;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值