杭电5645之DZY Loves Balls
2016-07-23 14:49
253 查看
[align=left]Problem Description[/align]
DZY loves playing balls.
He has n
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
A.
Next, without putting A
back into the box, he randomly picks another ball from the box, and names it
B.
If the number written on A
is strictly greater than the number on B,
he will feel happy.
Now you are given the numbers on each ball. Please calculate the probability that he feels happy.
[align=left]Input[/align]
First line contains t
denoting the number of testcases.
t
testcases follow. In each testcase, first line contains
n,
second line contains n
space-separated positive integers ai,
denoting the numbers on the balls.
(1≤t≤300,2≤n≤300,1≤ai≤300)
[align=left]Output[/align]
For each testcase, output a real number with 6 decimal places.
[align=left]Sample Input[/align]
2 3 1 2 3 3 100 100 100[align=left]Sample Output[/align]0.500000 0.000000
问题描述
分析:把所有球两两比较,第一个球大于第二个球的情况除以总情况n*(n-1),即得答案
AC代码如下:
DZY loves playing balls.
He has n
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
A.
Next, without putting A
back into the box, he randomly picks another ball from the box, and names it
B.
If the number written on A
is strictly greater than the number on B,
he will feel happy.
Now you are given the numbers on each ball. Please calculate the probability that he feels happy.
[align=left]Input[/align]
First line contains t
denoting the number of testcases.
t
testcases follow. In each testcase, first line contains
n,
second line contains n
space-separated positive integers ai,
denoting the numbers on the balls.
(1≤t≤300,2≤n≤300,1≤ai≤300)
[align=left]Output[/align]
For each testcase, output a real number with 6 decimal places.
[align=left]Sample Input[/align]
2 3 1 2 3 3 100 100 100[align=left]Sample Output[/align]0.500000 0.000000
问题描述
DZY喜欢玩球。 他有nn个球,装进一个大盒子里。每个球上面都写着一个整数。 有一天他打算从盒子中挑两个球出来。他先均匀随机地从盒子中挑出一个球,记为AA。他不把AA放回盒子,然后再从盒子中均匀随机地挑出一个球,记为BB。 如果AA上的数字严格大于BB上的数字,那么他就会感到愉悦。 现在告诉你每个球上的数字,请你求出他感到愉悦的概率是多少。输入描述
第一行tt,表示有tt组数据。 接下来tt组数据。每组数据中,第一行包含一个整数nn,第二行包含nn个用空格隔开的正整数a_iai,表示球上的数字。 (1\le t\le 300, 2\le n \le 300,1\le a_i \le 3001≤t≤300,2≤n≤300,1≤ai≤300)输出描述
对于每个数据,输出一个实数答案,保留6位小数。输入样例
2 3 1 2 3 3 100 100 100输出样例
0.500000 0.000000
分析:把所有球两两比较,第一个球大于第二个球的情况除以总情况n*(n-1),即得答案
AC代码如下:
#include "stdio.h" int main(int argc, char* argv[]) { int n,i,j,m,a[301],num; double res; scanf("%d",&n); while(n--) { num=0; scanf("%d",&m); for (i=0;i<m;i++) { scanf("%d",&a[i]); } for (i=0;i<m;i++) { for (j=0;j<m;j++) { if (a[i]>a[j]) { num++;//记录A>B的情况 } } } res=(double)num/(m*(m-1)); printf("%lf\n",res); } return 0; }
相关文章推荐
- 1587 - Box
- 小白笔记----------------判断一个数是不是某个数的次方
- HDU-5363 Key Set 【快速幂取模+递推】
- bnu 52037 Escape from Ayutthaya
- (转)Sqlite 管理工具 SQLiteDeveloper及破解
- FusionCharts--加载json文件
- [尺取法] poj 3061 Subsequence
- javascript针对DOM的应用(一)
- c++ 在windwos上创建盘符,并且,监控盘符里面任一文件的变动事件
- Codeforces Round #364 (Div. 2) B
- RecyclerView has no adapter, skip layout
- Android——《第一行代码》
- cocos2dx.3.x之重要类分析(3)——Scene
- jrMz and angles 暴力
- 深入理解java虚拟机(三):String.intern()-字符串常量池
- 谈谈8年C++面向对象设计的经验体会
- jQuery 怎么实现点击页面其他地方隐藏菜单?
- 手机浏览器上的特殊效果,如拨号、跳转地图app等
- 浅谈TCP/IP网络编程中socket的行为
- JavaScript 框架设计(二)