Poj3440--coin Toss (probability of geometry)

Source: Internet
Author: User

Topic Link: Click to open the link

The main topic: give the N*m a rectangle, each square side length is T, there is a coin, the diameter is C, randomly thrown to the rectangle ( Center in the rectangle ), there may appear in the figure of 5, that is, covering 1, 2, 3, 4 squares, ask coverage 1, 2, 3, What is the probability of 4 squares?

First consider the shape of the rectangle, divided into (1,n), (n,m)

for (1), the probability of A1 is 1, and the other is 0.

for (1,n) may cover 1, 2, respectively, consider each case, to find out the location of the center may exist, calculate the probability

for (n,m) may cover 1, 2, 3, 4, consider each case, and the position of the square (in the corner, on the edge, in the interior), calculate the position of the center may exist, calculate the probability, for 3 of the area is not good. Find the area of 1, 2, 4. Minus 1, they get 3 probability.

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std;  Define PI ACOs ( -1.0) int n, m;d ouble T, C, is;d ouble A1, A2, A3, A4; void Solve () {a1 = (t-c/2.0) * (t-c/2.0) *4.0    + (t-c/2.0) * (t-c) * (n-2+m-2) *2.0 + (t-c) * (t-c) * (n-2) * (m-2);    A1/= is;    A2 = (t-c) * (c/2.0) * ((n-1) *m+ (m-1) *n) *2.0 + (c/2.0) * (c/2.0) * (n-1+m-1) * *;    A2/= is;    a4 = (c/2.0) * (c/2.0) *pi* (n-1) * (m-1);    A4/= is;    A3 = 1.0-a1-a2-a4; return;}    int main () {int s, step = 0;    scanf ("%d", &s);        while (s--) {scanf ("%d%d%lf%lf", &n, &m, &t, &c);        if (n > M) swap (N,M);        is = t*t*n*m;            if (n = = 1 && m = = 1) {a1 = 1.0;        a2 = a3 = a4 = 0.0;            } else if (n = = 1) {a1 = t* (t-c/2.0) *2.0 + t* (t-c) * (m-2);            A1/= is;            A2 = 1.0-A1;        a3 = a4 = 0.0; } else Solve () ;        if (step) printf ("\ n");        printf ("Case%d:\n", ++step);        printf ("Probability of covering 1 tiles =%.4lf%%\n", a1*100);        printf ("Probability of covering 2 tiles =%.4lf%%\n", a2*100);        printf ("Probability of covering 3 tiles =%.4lf%%\n", a3*100);    printf ("Probability of covering 4 tiles =%.4lf%%\n", a4*100); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Poj3440--coin Toss (probability of geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.