LightOJ1317---Throwing Balls into the Baskets 解题心得
2015-08-21 20:27
603 查看
原题:
Description
You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the main game. In our game we were N people trying to throw balls into M identical Baskets. At each turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you will be given the value of N and M. For each player probability of throwing a ball into any basket successfully is P. Assume that there are infinitely many balls and the probability of choosing a basket by any player is 1/M. If multiple people choose a common basket and throw their ball, you can assume that their balls will not conflict, and the probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets after Kturns.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing three integers N (1 ≤ N ≤ 16), M (1 ≤ M ≤ 100) and K (0 ≤ K ≤ 100) and a real number P (0 ≤ P ≤ 1).P contains at most three places after the decimal point.
Output
For each case, print the case number and the expected number of balls. Errors less than 10-6 will be ignored.
Sample Input
2
1 1 1 0.5
1 1 2 0.5
Sample Output
Case 1: 0.5
Case 2: 1.000000
分析:
那个M完全没有用好吧,题目说这么长,完全就是在迷惑我们,结果就是 double ans = n*p*k;
代码:
Description
You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the main game. In our game we were N people trying to throw balls into M identical Baskets. At each turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you will be given the value of N and M. For each player probability of throwing a ball into any basket successfully is P. Assume that there are infinitely many balls and the probability of choosing a basket by any player is 1/M. If multiple people choose a common basket and throw their ball, you can assume that their balls will not conflict, and the probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets after Kturns.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing three integers N (1 ≤ N ≤ 16), M (1 ≤ M ≤ 100) and K (0 ≤ K ≤ 100) and a real number P (0 ≤ P ≤ 1).P contains at most three places after the decimal point.
Output
For each case, print the case number and the expected number of balls. Errors less than 10-6 will be ignored.
Sample Input
2
1 1 1 0.5
1 1 2 0.5
Sample Output
Case 1: 0.5
Case 2: 1.000000
分析:
那个M完全没有用好吧,题目说这么长,完全就是在迷惑我们,结果就是 double ans = n*p*k;
代码:
#include <stdio.h> #include <iostream> #include<cstdio> #include<iomanip> #include<cmath> using namespace std; int main() { int t; int kase = 0; cin >> t; int n, m, k; double p; while (t--) { kase++; cin >> n >> m >> k >> p; double ans = n*p*k; cout << "Case " << kase << ':'<<' ' << fixed << setprecision(6) << ans << endl; } return 0; }
相关文章推荐
- iOS开发——多线程篇——RunLoop
- 深入理解JavaScript系列(38):设计模式之职责链模式
- 可视化交互技术
- C语言产生随机字符串
- jenkins 构建配置
- BZOJ1051
- 分页控件
- Rnadom Teams
- Hadoop的web页面....简单翻译一下,熟悉熟悉
- redis-3.0.3配置参考
- Shell重定向&>file、2>&1、1>&2的区别
- hdu1019
- leetcode-124:Binary Tree Maximum Path Sum(Java)
- 文本输入控件
- Action、Action<T>、Func<T> 匿名函数的写法
- linux使用酷我在线听音乐
- leetcode-124:Binary Tree Maximum Path Sum(Java)
- 深入理解JavaScript系列(37):设计模式之享元模式
- 简单内存泄漏检测方法 解决 Detected memory leaks! 问题
- 修改linux文件权限命令:chmod