140825 ● bipartite

Source: Internet
Author: User
// Query the console using the binary method. write ("Enter data count:"); int n = convert. toint32 (console. readline (); int [] NO = new int [N]; int x = 0, y = n-1; // X and Y respectively assign values to the defined array (arrays in ascending order by default, otherwise, you must sort the array elements.) For (INT I = 0; I <n; I ++) {console. write ("input data {0 }:", I + 1); no [I] = convert. toint32 (console. readline ();} console. clear (); // clear the console. write ("Enter the number of queries:"); int sel = convert. toint32 (console. readline ()); // Bipartite while (Y> = x) {int ZJ = (x + y)/2; // ZJ is X, if (SEL = No [ZJ]) // determines whether the query value is an intermediate element of this group of elements {console. writeline ("No. {0} element! ", ZJ + 1); break;} else if (SEL <no [ZJ]) // the query value is smaller than the intermediate element, then, the first digit of the intermediate element serves as the maximum element {Y = ZJ-1;} else if (SEL> no [ZJ]) of the next element. // the query value is greater than the intermediate element, then, the last digit of the intermediate element serves as the minimum element of the next element {x = ZJ + 1 ;}}if (Y <X) {console. writeline ("No such count! ");}

 

140825 ● bipartite

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.