Combo Game Simple problem

Source: Internet
Author: User
Tags bitset cmath


Uva-11859-division Game

Topic Delivery: Division Game

AC Code:

#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD;Const intMAXN =10005;intN, M, T;intmatch[ -];//Put a number of rows into their true factor, that is, take away some of the vegetarian factor, that can be seen as a bunch of matches to take out a few, so it can be seen as a combination of Nim gameintCHU[MAXN];intTO[MAXN];//Calculate the number of elements per numbervoidInit () {//Hit the table to calculate the element factorto[1] =0; for(inti =2; i < MAXN; i + +) chu[i] = i; for(inti =2; i < MAXN; i + +) {if(To[i])Continue; To[i] + +; for(intj =2I J < Maxn; J + = i) { while(Chu[j]% i = =0) {To[j] + +;            CHU[J]/= i; }        }    }}intMain () {init ();intTscanf("%d", &t); for(intCAS =1; CAS <= T; CAS + +) {memset(Match,0,sizeof(match));scanf("%d%d", &n, &m); for(inti =1; I <= N; i + +) { for(intj =1; J <= M; J + +) {scanf("%d", &t);            Match[i] + = to[t]; }        }//Because the title can be considered as Nim game, so the SG value is the match value of the XOR and        intSG = match[1]; for(inti =2; I <= N;        i + +) {sg = sg ^ match[i]; }if(sg = =0)printf("Case #%d:no\n", CAs);//sg is 0 o'clock, the winner will be defeated, and vice versa.        Else printf("Case #%d:yes\n", CAs); }return 0;}


Uvalive-5059-playing with stones

Topic Transmission: Playing with stones

This problem can be a table to find the law.

To play the table code:

#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD;Const intMAXN = -;intSG[MAXN];intVIS[MAXN];intMain () {sg[1] =0;//Only one time can not be taken, for the state of defeat     for(inti =2; I <= -; i + +) {memset(Vis,0,sizeof(VIS)); for(intj =1; J *2<= i; J + +) Vis[sg[i-j]] =1; for(intj =0;; J + +)if(!vis[j]) {Sg[i] = j; Break; }printf("%d", Sg[i]); }return 0;}

The law is:
When n is even, SG (n) = N/2;
When n is odd, sg (n) = SG (N/2);

AC Code:

#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL Long Long#define INF 0x7fffffffusing namespace STD; ll SG (ll x) {return(X &1) ? SG (X/2): X/2;}intMain () {intTCin>> T; while(T-) {intN LL A, ans =0;Cin>> N; for(inti =0; I < n; i + +) {Cin>> A;        Ans ^= SG (a); }if(ANS)cout<<"yes\n";Else cout<<"no\n"; }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Combo Game Simple 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.