ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

吴永辉教授2021年讲课3-4

2021-03-12 21:34:11  阅读:251  来源: 互联网

标签:tiles Probability 吴永辉 covering double 讲课 2021 tile coin


目录

B Coin Toss

戳我.

Description
In a popular carnival game, a coin is tossed onto a table with an area that is covered with square tiles in a grid. The prizes are determined by the number of tiles covered by the coin when it comes to rest: the more tiles it covers, the better the prize. In the following diagram, the results from five coin tosses are shown:
在这里插入图片描述
In this example:
coin 1 covers 1 tile
coin 2 covers 2 tiles
coin 3 covers 3 tiles
coin 4 covers 4 tiles
coin 5 covers 2 tiles
Notice that it is acceptable for a coin to land on the boundary of the playing area (coin 5). In order for a coin to cover a tile, the coin must cover up a positive area of the tile. In other words, it is not enough to simply touch the boundary of the tile. The center of the coin may be at any point of the playing area with uniform probability. You may assume that (1) the coin always comes to a rest lying flat, and (2) the player is good enough to guarantee that the center of the coin will always come to rest on the playing area (or the boundary).
The probability of a coin covering a certain number of tiles depends on the tile and coin sizes, as well as the number of rows and columns of tiles in the playing area. In this problem, you will be required to write a program which computes the probabilities of a coin covering a certain number of tiles.

Input
The first line of input is an integer specifying the number of cases to follow. For each case, you will be given 4 integers m,n,t, and c on a single line, separated by spaces. The playing area consists of m rows and n columns of tiles, each having side length t. The diameter of the coin used is c. You may assume that 1≤m,n≤5000, and 1≤c<t≤1000.
Output
For each case, print the case number on its own line. This is followed by the probability of a coin covering 1 tile, 2 tiles, 3 tiles, and 4 tiles each on its own line. The probability should be expressed as a percentage rounded to 4 decimal places. Use the format as specified in the sample output. You should use double−precision floating−point numbers to perform the calculations. “Negative zeros” should be printed without the negative sign.
Separate the output of consecutive cases by a blank line.
Samples
Input
3
5 5 10 3
7 4 25 20
10 10 10 4
Output
Case 1:
Probability of covering 1 tile = 57.7600%
Probability of covering 2 tiles = 36.4800%
Probability of covering 3 tiles = 1.2361%
Probability of covering 4 tiles = 4.5239%
Case 2:
Probability of covering 1 tile = 12.5714%
Probability of covering 2 tiles = 46.2857%
Probability of covering 3 tiles = 8.8293%
Probability of covering 4 tiles = 32.3135%
Case 3:
Probability of covering 1 tile = 40.9600%
Probability of covering 2 tiles = 46.0800%
Probability of covering 3 tiles = 2.7812%
Probability of covering 4 tiles = 10.1788%

解析:我们解这个题的思路就是求硬币在哪些区域会压到几块方格,然后把这些区域的面积加起来除以总面积,便是硬币压到对应方格数的概率。
我们求这个面积的时候都是找与线相切时的位置的。然后找出边长即可求得面积。还有一点别再计算的过程中迷糊了就是他给的是硬币的直径!!

  • 压两块

在这里插入图片描述

  • 压三或四块
    在这里插入图片描述

  • 压一块
    在这里插入图片描述
    注意输出的格式:

  • tile tiles;

  • tile后有俩空格
    Code:

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const int N = 20;
const double pi = acos(-1.0);
int x,k=0,q;
double m,n,t,c;
int main() {
	cin>>x;
	q = x;
	while(x--) {
		scanf("%lf%lf%lf%lf",&m,&n,&t,&c);
		double s = n*m*t*t;
		double s2 = c*(t-c)*(2*m*n-n-m)+c*(c/2.0)*2*(m+n-2);
		double s4 = pi*c*c/4.0*(m-1)*(n-1);
		double s3 = (m-1)*(n-1)*c*c-s4;
		double s1 = s - s2 - s3 - s4;
		printf("Case %d:\n",++k);
		printf("Probability of covering 1 tile  = %.4lf%\n",s1/s*100);
		printf("Probability of covering 2 tiles = %.4lf%\n",s2/s*100);
		printf("Probability of covering 3 tiles = %.4lf%\n",s3/s*100);
		printf("Probability of covering 4 tiles = %.4lf%\n",s4/s*100);
		if(k!=q) putchar('\n');
	}
	return 0;
}

标签:tiles,Probability,吴永辉,covering,double,讲课,2021,tile,coin
来源: https://blog.csdn.net/m0_51376859/article/details/114703937

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有