If there are n balls with different numbers in the bag, is it possible to retrieve any two of the three balls without a serial number? (Downmoon)

Source: Internet
Author: User

Someone asked: Is there one ball in the bag that ranges from 1 to 10? If you want to retrieve three balls, do you have the chance that any two balls in the bag will not be connected? The invitation month took a try today. The algorithm is very general. We are looking forward to communication.

The approximate algorithm is a three-tier loop. One Ball is taken out first, and then any one is taken from the remaining ball, and then ******.

/// <Summary> <br/> /// the bag contains N balls with different numbers. You can retrieve three balls at will, calculate the probability that two balls in three balls are not connected <br/> // by Tony 200909.17 <br/> // <a Title = "" href = "http://blog.csdn.net/downmoon/" mce_href = "http://blog.csdn.net/downmoon/"> welcome to the invitation to exchange, NET technology and software architecture </a> (monthly invitation) 3w@live.cn <br/> // </Summary> <br/> // <Param name = "orgint"> an integer array column </param> <br/> Public static void getprobability (INT [] orgint) <br/>{< br/> int length = orgint. length; <br/> I NT all = 0; // total number of all <br/> int rel = 0; // The total number of adjacent records <br/> foreach (int fi in orgint) <br/> {<br/> // retrieves a ball from the array of length numbers, number: fi <br/> int [] secint = new int [length-1]; <br/> // obtain the array of the remaining nine numbers <br/> int [] temp1 = new int [orgint. length]; <br/> temp1 = (INT []) orgint. clone (); <br/> int T1 = 0; <br/> foreach (INT R1 in temp1) <br/>{< br/> If (Fi! = R1) <br/>{< br/> secint [T1] = R1; <br/> T1 ++; <br/>}< br/> int [] thint = new int [secint. length-1]; <br/> foreach (INT Si in secint) <br/>{< br/> // retrieves a ball from the remaining length-1 number array, number is SI <br/> // obtain the remaining eight number arrays <br/> // console. writeline (FI + "+" + Si + "+"); <br/> int [] temp2 = (INT []) secint. clone (); <br/> int t2 = 0; <br/> foreach (INT R2 in temp2) <br/>{< br/> If (Si! = R2 & R2! = Fi) <br/>{< br/> thint [T2] = R2; <br/> T2 ++; <br/>}< br/> foreach (INT Ti in thint) <br/>{< br/> // you can retrieve a ball from the remaining length-2 number arrays. The number is Ti. <br/> If ((! Isrel (Ti, Si ))&&(! Isrel (FI, Si ))&&(! Isrel (FI, Ti) <br/>{< br/> rel ++; <br/> console. writeline (FI + "+" + Si + "+" + Ti); <br/>}< br/> // This can be obtained by external computation, to save resources <br/> // All ++; <br/>}< br/> All = length * (length-1) * (length-2 ); <br/> console. writeline ("two balls in three balls are not connected:" + REL +! "); <Br/> console. writeline (" all possible three-ball removal: "+ all +! "); <Br/> console. writeline ("the probability that any two of the three balls are not connected:" + (double) REL/All ). tostring (); <br/> console. readkey (); <br/>}< br/> /// <summary> <br/> // compare the adjacent values. <br/> /// </Summary> <br/> /// <Param name = "A"> </param> <br/> // <Param name = "B"> </param> <br/> // /<returns> </returns> <br/> Public static bool isrel (int, int B) <br/>{< br/> If (a + 1) = B) {return true ;}< br/> If (A-1) = B) {return true ;}< br/> return false; <br/>}

Test:

Public static void main (string [] ARGs) <br/>{< br/> int [] orgint = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; <br/> getprobability (orgint); <br/>}

Test results:

1 + 10 + 7 <br/> 1 + 10 + 8 <br/> 2 + 4 + 6 <br/> 2 + 4 + 7 <br/> 2 + 4 + 8 <br/> 2 + 4 + 9 <br/> 2 + 4 + 10 <br/> 2 + 5 + 7 <br/> 2 + 5 + 8 <br/> 2 + 5 + 9 <br/> 2 + 5 + 10 <br/> 2 + 6 + 4 <br/> 2 + 6 + 8 <br/> 2 + 6 + 9 <br/> 2 + 6 + 10 <br/> 2 + 7 + 4 <br/> 2 + 7 + 5 <br/> 2 + 7 + 9 <br /> 2 + 7 + 10 <br/> 2 + 8 + 4 <br/> 2 + 8 + 5 <br/> 2 + 8 + 6 <br/> 2 + 8 + 10 <br/> 2 + 9 + 4 <br/> 2 + 9 + 5 <br/> 2 + 9 + 6 <br/> 2 + 9 + 7 <br/> 2 + 10 + 4 <br/> 2 + 10 + 5 <br/> 2 + 10 + 6 <br/> 2 + 10 + 7 <br/> 2 + 10 + 8 <br/> 3 + 1 + 5 <br/> 3 + 1 + 6 <br/> 3 + 1 + 7 <br/> 3 + 1 + 8 <br/> 3 + 1 + 9 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 1 <br/> 9 + 5 + 2 <br/> 9 + 5 + 3 <br/> 9 + 5 + 7 <br/> 9 + 6 + 1 <br/> 9 + 6 + 2 <br/> 9 + 6 + 3 <br/> 9 + 6 + 4 <br/> 9 + 7 + 1 <br/> 9 + 7 + 2 <br/> 9 + 7 + 3 <br/> 9 + 7 + 4 <br/> 9 + 7 + 5 <br/> 10 + 1 + 3 <br/> 10 + 1 + 4 <br/> 10 + 1 + 5 <br/> 10 + 1 + 6 <br /> 10 + 1 + 7 <br/> 10 + 1 + 8 <br/> 10 + 2 + 4 <br/> 10 + 2 + 5 <br/> 10 + 2 + 6 <br/> 10 + 2 + 7 <br/> 10 + 2 + 8 <br/> 10 + 3 + 1 <br/> 10 + 3 + 5 <br/> 10 + 3 + 6 <br/> 10 + 3 + 7 <br/> 10 + 3 + 8 <br/> 10 + 4 + 1 <br/> 10 + 4 + 2 <br/> 10 + 4 + 6 <br/> 10 + 4 + 7 <br/> 10 + 4 + 8 <br/> 10 + 5 + 1 <br/> 10 + 5 + 2 <br/> 10 + 5 + 3 <br/> 10 + 5 + 7 <br/> 10 + 5 + 8 <br/> 10 + 6 + 1 <br/> 10 + 6 + 2 <br/> 10 + 6 + 3 <br/> 10 + 6 + 4 <br/> 10 + 6 + 8 <br/> 10 + 7 + 1 <br/> 10 + 7 + 2 <br/> 10 + 7 + 3 <br/> 10 + 7 + 4 <br/> 10 + 7 + 5 <br/> 10 + 8 + 1 <br/> 10 + 8 + 2 <br/> 10 + 8 + 3 <br/> 10 + 8 + 4 <br/> 10 + 8 + 5 <br/> 10 + 8 + 6

There are 336 possibilities of No-match between two balls in three balls!

All the three-ball removal possibilities are as follows: 720!

The probability of no connection to any two of the three balls is: 0.466666666666667.

Thank you for your correction.

After reading the replies, it seems that my analysis is not clear enough. At the beginning of this article, the ball 1-10 is a serial number. In my algorithm, numbers are not differentiated,

That is to say, my algorithms are generic and have nothing to do with specific numbers.

Test:

Public static void main (string [] ARGs) <br/>{< br/> int [] orgint = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11 };< br/> getprobability (orgint); <br/>}

 

Change the original number 10 to 11, then the answer is

The possibility of disconnecting two balls in three balls is as follows: 378

Type!

All the three-ball removal possibilities are as follows: 720!

The probability of no connection to any two of the three balls is: 0.525.

Public static void main (string [] ARGs) <br/>{< br/> int [] orgint = {1, 2, 3, 4, 5, 6, 7, 8, 13, 11 };< br/> getprobability (orgint); <br/>}



Change the original number 10 to 11 and the original number 9 to 13, then the answer is changed

The possibility of disconnecting two balls in three balls is as follows: 420

Type!

All the three-ball removal possibilities are as follows: 720!

The probability of no connection to any two of the three balls is: 0.525.

 


Helping others is the same as self-help! 3w@live.cn

 

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.