首页 > ACM题库 > HDU-杭电 > HDU 3569-Imaginary Date[解题报告]HOJ
2014
11-27

HDU 3569-Imaginary Date[解题报告]HOJ

Imaginary Date

问题描述 :

XMM met his ex-girlfriend on Double Seventh Festival Day. Though what happened between these two little kids was in the past, there did exist some strange and complicated feelings or something you can call it desire, which XMM cannot deny and tried as hard as he can to keep those things inside to ensure nobody else knows. But as his friends, just to be clear, it is so obvious to us.

So, today is a day. How could XMM possibly give up this wonderful chance? He once again asked XLZ out and then took her to a nice restaurant and prepared to give some delicious chocolate to XLZ to satisfy her which we think is useless.

There are n kinds of chocolate in the restaurant, XLZ likes them in varying degrees. To simplify this, every chocolate have a integer value vi(1 <= vi <= 1000 for all 1 <= i <= n <= 1000). This implies how much XLZ likes it. But since it has been such a long time that XMM Broke up with XLZ, XMM didn’t know it. So he’d like to randomly choose a chocolate every minute to give it to her. The total time XMM has is m minutes (1 <= m <= 1000).But there is another restriction: the kitchen is not so effective so after XMM buy a chocolate, it needs k (1 <= k <= n) minutes to make this kind of chocolate which means the next time XMM can order this is at least k minutes later.

Now we want to know the expect value XLZ gets on that special night.

输入:

The first line is a single integer T indicating the number of cases that follow.
For each case, three integers n, m, k are give in the first line which is mentioned above.
The next line contains n integers which are the value of the n chocolates.

输出:

The first line is a single integer T indicating the number of cases that follow.
For each case, three integers n, m, k are give in the first line which is mentioned above.
The next line contains n integers which are the value of the n chocolates.

样例输入:

2

3 3 1
1 3 5

4 4 4
1 2 3 4

样例输出:

Case 1: 9.00000
Case 2: 10.00000

#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,n,m,k,h,t,x;
	double sum=0.0;
	scanf("%d",&t);
	for(h=1;h<=t;h++)
	{
		scanf("%d%d%d",&n,&m,&k);
		sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&x);
			sum+=x;
		}
		sum=1.0*sum*m/n;
		printf("Case %d: %.5lf\n",h,sum);
	}
	return 0;
}

  1. 有两个重复的话结果是正确的,但解法不够严谨,后面重复的覆盖掉前面的,由于题目数据限制也比较严,所以能提交通过。已更新算法