Blue Bridge cup (game probability)

Source: Internet
Author: User
Package com. lanqiaobei. dati_01; import java. util. Random. Suppose there are four teams: Team A, Team B, Team C, and team D. Based on their previous results, we can draw a table showing the probability that each team will win against another team: a, B, C, D, a, a, 0.1, 0.3, B, 0.5, 0.9, 0.7, 0.4, 0.7, 0.3, 0.2, 0.5, 0.6, 0.8, 0.1, the victory rate of C for B is 0.3 ,... A championship is now to be held. The two sides drew lots and divided them into two groups to compete for the championship. (See Figure 1.jpg). Please perform a 0.1 million simulation to calculate the probability that the team a won the championship. Note: Perform debugging carefully! Your Program You have a chance to score only when you can run the correct result! */Public class duoguangailv {/*** @ Param ARGs * @ author wildcat * // defines a two-dimensional array, public static double GL [] [] = {1, 0.1, 0.3, 0.5}, {0.9, 1, 0.7, 0.4}, {0.7, 0.3, 1, 0.2 },{ 0.5, 0.6, 0.8, 1 }}; public static int mamber [] = }; // It is used to represent the four players' public static void main (string [] ARGs) {// todo auto-generated method stubdouble asuccess = 0; // perform 1000000 Simulation for (INT I = 0; I <1000000; I ++) {asuccess + = getresult ();} system. out. prin TLN (asuccess/1000000);} public static double getresult () {int enemy = getenemy (); // obtain the opponent's double su1 = pkaandb (0, enemy) by drawing lots ); // The probability that a wins the first opponent is int p1 = 0, P2 = 0; // represents the two teams in the other group for (INT I = 1; I <4; I ++) {If (enemy! = I & p1 = 0) {// The first p1 = I;} else if (enemy! = I) {P2 = I ;}} double nother = pkaandb (P1, P2); // The probability that P1 in another group wins double result = su1 * nother * pkaandb (0, p1) + su1 * (1-nother) * pkaandb (0, P2); // returns the probability of winning a in a game. Return result ;} // obtain the opponent public static int getenemy () {random Ra = new random (); Return Ra. nextint (3) + 1;} // a returns the probability of a winning in B. Public static double pkaandb (int A, int B) {return GL [a] [B] ;}}

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.