Dichotomy Method C #

Source: Internet
Author: User

Two-part method

Example: Look at the price of goods

First show a product priced at 999 yuan, the participants to guess the price of the goods. In the process of guessing the price, the referee will give more participants the price, corresponding to the "high" or "low" hint.

Table 1-1 Two-way guess commodity price (640)

Number

Price range

Middle Value

1th time

0~999

500

2nd time

500~999

750

3rd time

500~750

620

4th time

620~750

680

5th time

620~680

650

6th time

620~650

630

7th time

630~650

640

//0~999 guess the priceConsole.WriteLine ("Please enter the price of the product:"); intCommoditprices =convert.toint16 (Console.ReadLine ()); Console.WriteLine ("participants:"); intprices=convert.toint16 (Console.ReadLine ()); intI=1;  while(true) {i++; if(prices<commoditprices) {Console.WriteLine ("it's low."); Console.WriteLine ("participants:"); Prices=convert.toint16 (Console.ReadLine ()); }               Else if(prices>commoditprices) {Console.WriteLine ("High."); Console.WriteLine ("participants:"); Prices=convert.toint16 (Console.ReadLine ()); }               Else{Console.WriteLine ("Congratulations, guess right, guess {0} times in total. ", i);  Break; }} console.readkey ();

Dichotomy Method C #

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.