poj1740 A New Stone Game

Source: Internet
Author: User

Test instructions: For n heap of stones, each pile of several, two people in turn, each operation in two steps, the first step from a heap to remove at least one, the second step (can be omitted) to the heap of the remaining stones part of the other heap.

Really good ♂ problem, code is not long is good ♂ problem.

First of all, consider two piles of the same stone, the initiator must lose, because if I operate the first pile, then the second pile can also make a symmetric decision.

In fact, other circumstances, must be the initiator win.

First case: Odd heap.

We can assign the maximum heap of pebbles to the other heaps so that they are 22 paired, as shown in:

Obviously, the red part of the cliff will not exceed the height of the fifth stone.

Second case: even case

We can pair the largest heap with the smallest one, and the rest of the pile will be matched with the n-2 heap of stones.

Emma:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <string>6#include <algorithm>7 intn,f[205],x;8 intMain () {9      while(SCANF ("%d", &n) &&N) {Ten         intCnt=0; OneMemset (F,0,sizeoff); A          for(intI=1; i<=n;i++){ -scanf"%d",&x); -             if(!f[x]) cnt++,f[x]=1; the             ElseCNT--, f[x]=0; -         } -         if(!cnt) printf ("0\n"); -         Elseprintf"1\n"); +     } -}

poj1740 A New Stone Game

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.