BestCoder Round #76 (div.2) DZY Loves Balls

DZY Loves Balls

 
 Accepts: 662
 
 Submissions: 1393
 Time Limit: 4000/2000 MS (Java/Others)
 
 Memory Limit: 262144/262144 K (Java/Others)
Problem Description

DZY loves playing balls.

He has nn balls in a big box. On each ball there is an integer written.

One day he decides to pick two balls from the box. First he randomly picks a ball from the box, and names it AA. Next, without putting AA back into the box, he randomly picks another ball from the box, and names it BB.

If the number written on AA is strictly greater than the number on BB, he will feel happy.

Now you are given the numbers on each ball. Please calculate the probability that he feels happy.

Input

First line contains tt denoting the number of testcases.

tt testcases follow. In each testcase, first line contains nn, second line contains nn space-separated positive integers a_iai, denoting the numbers on the balls.

(1\le t\le 300, 2\le n \le 300,1\le a_i \le 3001t300,2n300,1ai300)

Output

For each testcase, output a real number with 6 decimal places.

Sample Input
2
3
1 2 3
3
100 100 100
Sample Output
0.500000
0.000000
 
    
一道求期望的水题~~~~~~~~~~~~~~~~~~~~~~~~~·
 
    
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int t, sq[1000], n;
bool cmp(int x, int y)
{
	return x < y;
}
int same(int x) {
	if((x + 1) < n && sq[x] == sq[x + 1])
		return 1 + same(x + 1);
	return 0;
}
int main()
{
	scanf("%d", &t);
	while (t--) {
		double ans = 0;
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			scanf("%d", &sq[i]);
		}
		sort(sq, sq + n,cmp);
		for (int i = 0; i < n; i++) {
			if(same(i)) {
				ans += n -1 - i - same(i);
			}
			else ans += n - i - 1;
		}
		printf("%lf\n", ans / (n * (n - 1)));
	}
	return 0;
} 


转载于:https://www.cnblogs.com/cniwoq/p/6770967.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Process: com.example.dzy, PID: 26008 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dzy/com.example.dzy.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at com.example.dzy.Fragment_1.<init>(Fragment_1.java:44) at com.example.dzy.NavigationActivity.initTab(NavigationActivity.java:39) at com.example.dzy.NavigationActivity.onCreate(NavigationActivity.java:27) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
最新发布
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值