Poj 3440 coin toss

Source: Internet
Author: User

The geometric Summary of High School probability is also called a question, but the output is really pitfall.


Question:

A rectangle consisting of n * m square with a side length of T. I threw a coin with a diameter of C on the rectangle and asked what is the probability of covering 1, 2, and 4 Rectangles?


Solution:

It is calculated that the center of the coin can be located in the area of the circle that covers 1, 2, and 3 rectangles. Then we can find the probability ~



The following code is used:

# Include <set> # include <map> # include <queue> # include <math. h> # include <vector> # include <string> # include <stdio. h> # include <string. h> # include <stdlib. h >#include <iostream> # include <algorithm> # define EPS 1e-6 # define PI ACOs (-1.0) # define INF 107374182 # define inf64 1152921504606846976 # define LC l, m, tr <1 # define RC m + 1, R, TR <1 | 1 # define iabs (x)> 0? (X):-(x) # define clear1 (A, X, size) memset (A, X, sizeof (A [0]) * (size )) # define clearall (A, x) memset (A, X, sizeof (A) # define memcopy1 (A, X, size) memcpy (A, X, sizeof (X [0]) * (size) # define memcopyall (A, x) memcpy (A, X, sizeof (x) # define max (x, y) (x)> (y ))? (X): (y) # define min (x, y) (x) <(y ))? (X): (y) using namespace STD; int main () {int T, case1 = 1; double n, m, T, C, ANS [4]; scanf ("% d", & T); While (t --) {scanf ("% lf", & N, & M, & T, & C); ans [0] = (t-C/2) * (t-C/2) * 4 + (t-c) * (t-C/2) * (2 * m + 2 * n-8) + (t-c) * (n-2) * (m-2 ); // when a square is covered, the circle center of the coin can be in the location ans [2] = (C * C-Pi * (C/2) * (C/2) * (n-1) * (m-1); ans [3] = pI * (C/2) * (C/2) * (n-1) * m-1 ); ans [1] = N * m * T * t-ans [0]-ans [2]-ans [3]; printf ("case % d: \ n ", case1 ++); printf ("probability of covering 1 tile = %. 4f % \ n ", ANS [0] * 100.0/(n * m * T * t); For (INT I = 1; I <4; I ++) {printf ("probability of covering % d tiles = %. 4f % \ n ", I + 1, ANS [I] * 100.0/(n * m * T * t);} puts ("");} return 0 ;}


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.