A and B play games with the same string of numbers

Source: Internet
Author: User

A and B use the same string of numbers to play the game. There are 15 games in total. In the beginning, these numbers are not strictly ascending. A removes one data. If the numbers are strictly ascending, a wins, otherwise, Party B will continue to remove the data. If the data is strictly in ascending order, Party B will win the game. Otherwise, Party A will delete the data again. Determine whether a wins or B wins based on 15 initial data records.

# Include <iostream> # include <list> using namespace STD; bool SUP (list <int> & L) // determine whether the condition is strictly ascending {If (L. size () = 1) {return true;} else {list <int >:: iterator iter1, iter2; iter1 = L. begin (); iter2 = L. begin (); ++ iter2; while (iter2! = L. end () {If (* iter1> = * iter2) {return false;} + + iter1; ++ iter2;} return true ;}} bool func (list <int> L) {list <int>: iterator ITER; For (iter = L. begin (); iter! = L. end ();) // remove any one of the list to see if it can be strictly ascending {int temp = * ITER; L. erase (ITER ++); If (SUP (L) {return true;} l. insert (ITER, temp);} For (iter = L. begin (); iter! = L. end ();) // if any one is removed, it cannot be strictly ascending. If any one is removed, check whether Party B can win {int temp = * ITER; L. erase (ITER ++); If (! Func (L) // Party B cannot win, that is, Party A wins {return true;} l. insert (ITER, temp);} return false; // B wins in all cases} int main () {int Buf [] = {, 5 }; list <int> L; For (INT I = 0; I <sizeof (BUF)/sizeof (INT); I ++) {L. push_back (BUF [I]);} If (func (L) {cout <"true" <Endl ;} else {cout <"false" <Endl;} return 0 ;}

 

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.