sdutoj3112-Xiao Xin's love story _ Game theory

Source: Internet
Author: User
Xiao Xin's love story time limit:1000ms Memory limit:65536k have doubts. Point here ^_^ topic description After unremitting efforts, Xiao Xin finally chased the goddess mm, one day the goddess to test the IQ of Xiao Xin, and Xiao Xin played a game. They took out n stones and put them in a column. The game, each time only from the left a row of stones at the beginning, take one or two stones, the goddess let Xiao Xin take first. When the last one is finished, there is no stone even if he wins the game. Xiao Xin don't want to lose face in front of the goddess, so he asked you to help him in advance to calculate whether you can win, if you can win the output "you win" otherwise output "you lose". We think Xiao Xin and her goddess are smart enough. Each decision is the most reasonable. Enter a positive integer n (1 <= n <= 300). Output if Xiao Xin can win output "you win", otherwise output "you lose" sample input
1
7
Sample output
You win your
win
Hint This problem we can think so, if the beginning only 1 or 2 stones, then Xiao Xin win, if the beginning is 3 stones, no matter how small Xin how to take, will be defeated. If the first is 4 or 5 stones, so small Xin first Take 1 or 2 stones, regardless of the goddess take a few stones, Xiao Xin will win, so we can find the law, that is, when the number of stones as a multiple of 3, small Xin will be defeated, other times Xiao Xin will win. This is a typical game theory problem, you can study it if you are interested.

Code
#include <cstdio>

int main ()
{
    int n;
    while (~SCANF ("%d", &n))
    {
        if (n%3==0)
            printf ("You lose\n");
        else
            printf ("You win\n");
    }
    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.