Hdu 1809 evaluate SG Function

Source: Internet
Author: User

A New Tetris Game (2) Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission (s): 794 Accepted Submission (s ): 275 Problem Description Since Lele invented A New class Russian Game A New Tetris Game, he has been playing all night, and now gradually, he finds that this Game is also not so, in order to increase the difficulty, he developed a new set of rules: first, Lele and her sister took out N rectangular boards, some of which were unavailable and the rest were available. Each time Lele and her sister take turns to select a board from N boards and take out the square blocks in the Russian square (a square block of 2*2) and put them in the board, it should be noted that the square blocks to be put in cannot be stacked on the unavailable lattice of the Board, nor on the already placed square blocks. At the end of the day, whoever can no longer put square blocks will lose. Now, if every time Lele and her sister are very smart, they can put squares according to the optimal strategy, and each time they are put first in the square, can you tell him whether he will win his sister? Input this question contains multiple groups of tests, please process until the end of the file. The first line of each group of tests contains a positive integer N (N <30), indicating the number of inputs to the checkerboard. Next there are N checkerboard descriptions. For each board, the first line has two integers, R, C (R * C <50), representing the number of rows and columns of the Board respectively. Then there is the R Line. Each line contains C characters to represent this board. 0 indicates that the position of the board is available. 1 indicates that the position of the board is unavailable. You can assume that the number of 0 in each board is no more than 40. Output for each group of tests, if Lele is sure to win, Output "Yes" in a row; otherwise, Output "No ". Sample Input24 400000000000000004 4000000100100000014 40000001001000000 Sample OutputYesNo Authorlinle SourceHDOJ 2007 Summer Exercise (2) idea: Find the template idea based on the template of the sg function.

# Include <stdio. h> # include <string. h ># include <string >#include <map> using namespace std; int n, m; map <string, int> vis_str; map <string, int> sg; string s; void add (int a [] [50]) // convert the matrix into a string {int I, j; s = ""; for (I = 0; I <n; I ++) for (j = 0; j <m; j ++) s + = a [I] [j] + '0 ';} int mex (int a [] [50]) {int I, j, k; int vis_sg [100]; // the built-in array cannot be global memset (vis_sg, 0, sizeof (vis_sg); add (a); vis_str [s] = 1; for (I = 1; I <n; I ++) for (j = 1; j <m; j ++ ){ If (a [I] [j] = 0 & a [I-1] [j] = 0 & a [I] [J-1] = 0 & [i-1 [J-1] = 0) {a [I] [j] = a [I-1] [j] = a [I] [J-1] = a [I-1] [J-1] = 1; add (); if (vis_str [s]) k = sg [s]; else k = mex (a); vis_sg [k] = 1; a [I] [j] = a [I-1] [j] = a [I] [J-1] = a [I-1] [J-1] = 0 ;}} for (I = 0; I ++) {if (! Vis_sg [I]) {add (a); sg [s] = I; return I ;}} int main () {int I, j, a [50] [50], t, ans; while (scanf ("% d", & t )! = EOF) {ans = 0; while (t --) {scanf ("% d", & n, & m); for (I = 0; I <n; I ++) for (j = 0; j <m; j ++) scanf ("% 1d", & a [I] [j]); // sg. clear (); in addition to these two sentences, the query times out. // vis_str.clear (); ans = ans ^ mex (a);} if (ans) printf ("Yes \ n"); else printf ("No \ 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.