POJ 2287 Field bogey horse racing greedy algorithm

Source: Internet
Author: User

Tian Bogey horse race, roughly test instructions is Tian Bogey and King Horse racing, win a innings 200 yuan, lose a game lose 200 yuan, draw property does not move.

Enter an integer n, and the next line is the N horse of Tian Bogey, and the next line is the King's N horse. When n is 0 o'clock end. This is titled Greedy algorithm solution, there are two ideas. Thought two: 1, beginning is also the first sort, you can use sort quick row, 2, then the biggest horse and the king of the field to compare; 3, if Tian bogey the largest horse than the king, then on the Victory field ++;4, if the biggest Maxiau king, then will lose, so with Tian bogey the smallest horse to the king's largest horse; If the biggest horse of Tian bogey equals the king, then the smallest horse; 5. 1, if Tian bogey the smallest horse greater than the king, then win field ++;5. 2, if Tian bogey the smallest Maxiau king, then lose to the king; 5. 3, if Tian bogey the smallest horse is equal to the king, with Tian bogey the smallest horse to the king's biggest horse, if the King's largest horse, then the property to reduce 200;
Const intMax =1050; BOOLcmpintAintb) {returnA >b;} intPk2 () {intTian[max],king[max]; inti,j,n,m;  while(Cin >>N) {if(n = =0) Break;  for(i=1; i<=n; i++) {cin >>tian[i];}  for(i=1; i<=n; i++) {cin >>king[i];} Sort (Tian+1, tian+1+n,cmp); Sort (King+1, king+1+n,cmp); intAns =0; intII,JJ;  for(i=1, j=1, Ii=n, Jj=n; i<=II;) {     if(Tian[i] > King[j]) {ans + = -; i++,j++; } Else if(Tian[i] < king[j]) {ans-= -; j++,ii--; } Else     {      if(Tian[ii] >KING[JJ]) {ans+= -; II--, jj--; }       Else      {       if(Tian[ii] <King[j]) ans-= -; II--, J + +; } }} cout<< ans <<Endl; }    return 0; }intMain () {PK2 (); return 0;}

Reference:

http://blog.163.com/zhaoyuan_sue/blog/static/20868323120125280842774/

POJ 2287 Field bogey horse racing greedy algorithm

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.