Niu Ke pen exam, Niu Ke exam

Source: Internet
Author: User

Niu Ke pen exam, Niu Ke exam

Today, Alice and Bob have invented a new stone game. We place n stones in one row. Each stone from left to right has two parameters: energy ei and scoring ai. Alice and Bob take turns to make decisions, taking stones from left to right, and Alice takes the lead. For each round, players can choose one of the following two operations: 1. consume one unit of energy and skip this round. 2. Take the stones at the current position. At the beginning, Alice and Bob respectively had A and B units of energy. Both players aimed to maximize their scores. Both sides made the best decision and asked when the game was over, alice and Bob have different scores.

Given the question A and B (0 ≤ A ≤ 10 ^ 9, 0 ≤ B ≤ 10 ^ 9), and given the number of stones n (1 ≤ n ≤ 100), from left to right, energy e and score a for each stone (all numbers are positive integers, all elements in e are less than or equal to 10 ^ 9, and the sum of elements in a is less than or equal to 100 ). Please return an array where the first element is Alice's score and the second element is Bob's score.

Test example:
9,0,7,[66,2,6,2,8,4,3],[7,12,65,7,4,40,15]
Return Value: [112,38]


# Include <vector> class GetT {public: // objective to maximize the void Get (int & A, int & B, int N, int * e, int *, int re []) {// first-hand int * pCurPer = & A; int curPer = 1; int cur = 0; while (cur <N) {// be energetic and determine the value of the next round // if (Magic () & NextIsBetter ()) if (* pCurPer & a [cur + 1]> a [cur]) {(* pCurPer) --; GetNext (pCurPer, curPer, A, B); continue ;} else {// obtain the energy and score. * PCurPer + = e [cur]; re [curPer] + = a [cur]; GetNext (pCurPer, curPer, A, B); cur ++ ;} // obtain the stones at the current position. } Void GetNext (int * & cur, int & curper, int & p, int & q) {curper =! Curper; if (cur ==& p) {cur = & q;} else {cur = & p ;}}};

 

Test:

void main(){    int A = 9;    int B = 0;    const int s = 7;    int see[] = { 66, 2, 6, 2, 8, 4, 3 };    int sea[] = { 7, 12, 65, 7, 4, 40, 15 };    int re[] = {0,0};    GetT get;    get.Get(A, B, s, see, sea,re);    cout << re[0] << "\t";    cout << re[1] << endl;}

Running result

 

112 38
Press any key to continue...

Related Article

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.