51nod Game Theory Water problem

Source: Internet
Author: User

51nod1069 Nim Games

There are n heaps of stones. A B Two people take turns, a take first. Each time can only from a bunch of a few, can be a bunch of all take away, but not to take, the last 1 stones to win the people. Suppose a B is very clever, there is no mistake in the process of taking the stone. Give the number of N and each heap of stones, and ask who can win the game at the end. For example: 3 piles of gravel, 1 capsules per heap. A take 1, B take 1, at this time there are 1 piles left, so a can get the last 1 stones.
/* For a situation (A1,A2,..., an), if a1^a2^...^an<>0, there must be some legal movement, the AI will be changed into AI ' after A1^a2^...^ai ' ^...^an=0. As a a1^a2^...^an=k, there must be an AI, whose binary representation is 1 at the top of the K (otherwise the highest bit of k is how the 1 is obtained). Then Ai^k<ai must be set up. Then we can change AI to Ai ' =ai^k, at this time A1^a2^...^ai ' ^...^an=a1^a2^...^an^k=0. *///O (n) to find a winning strategy. #include <cstdio> #include <cstring> #include <cctype> #include <algorithm>using namespace std; #define REP (i,s,t) for (int i=s;i<=t;i++) int read () {int X=0;char C=getchar (), while (!isdigit (c)) C=getchar (), while ( IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} int main () {int n=read (), T,ans=0;rep (i,1,n) ans^= (T=read ()), if (ans) puts ("A"), Else puts ("B"); return 0;}

51nod1067 Bash Game V2

There are a bunch of stones in total N. A B Two people take turns, a take first. Each time can only take 1,3,4, to get the last 1 stones of the people to win. Suppose a B is very clever, there is no mistake in the process of taking the stone. Give N and ask who can win the game at the end. For example n = 2. A can only take 1, so B can get the last 1 stones.
101111010111101011110#include<cstdio> #define REP (i,s,t) for (int i=s;i<=t;i++) int main () {int n,u;scanf ("%") D ", &n); Rep (i,1,n) {scanf ("%d ", &u); U%=7;if (u==2| | u==0) puts ("B"); else puts ("A");} return 0;}

51nod1185 Witzov Game V2

There are 2 piles of stones. A B Two people take turns, a take first. Each time you can take any or 2 of the same number of stones from a heap, but not to be taken. The man who got the last 1 stones won. Suppose a B is very clever, there is no mistake in the process of taking the stone. Give the number of 2 stones and ask who will win the game at the end. For example, 2 stones were 3 and 5. So no matter a how to take, B has a corresponding method to get the last 1.
It is related to the Golden Section to find the law of the table. This card accuracy needs to be simulated multiplication ... Good God's analog multiplication ... #include <cstdio> #include <cstring> #include <cctype> #include <algorithm> #include <cmath >using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define ll long Longll Read () {ll x=0;char C=getchar (); while (!isdigit (c)) C=getchar (); while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x;} LL Ans[3]={618033988,749894848,204586834};const ll Mod=1e9;int main () {int t=read (); LL a,b,aa,ab,ac,ad,ba,bb;double TP = (sqrt (5) +1)/2;while (t--) {a=read (), B=read (); if (a>b) swap (A, b); Ba= (b-a)/mod,bb= (b-a)%mod;aa=bb*ans[2];ab=ba* Ans[2]+aa/mod+bb*ans[1];ac=ba*ans[1]+ab/mod+bb*ans[0];ad=b-a+ba*ans[0]+ac/mod;if (Ad==a) puts ("B"); else puts ("a") ;} return 0;}

  

51nod Game Theory Water problem

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.