Ultraviolet A 141-the spot game

Source: Internet
Author: User

In fact, it is required to compare four graphs (three of which are obtained by rotation flip) each time. Then, if none of the four figures have been shown before, all the four images will be saved, for future comparison (Note that if the original image is the same as the original image after rotation, this situation is not repeated ). At the beginning, it was understood that only the original image was saved after several comparisons, WA several times. Method: because the data size is small, the two-dimensional graph is directly saved as a one-dimensional array, and then the violent enumeration can be compared.

The Code is as follows:

# Include <iostream> # include <algorithm> # include <cstring> # include <cstdlib> # include <cstdio> # include <cmath> using namespace std; const int MAXSIZE = 2505; int n, num, cct; char a [52] [52], B [52] [52], c [405] [MAXSIZE]; void Hash () // convert a two-dimensional array to a one-dimensional array and save it {int cct =-1; for (int I = 1; I <= n; I ++) for (int j = 1; j <= n; j ++) c [num] [++ cct] = B [I] [j]; ++ num ;} int Search () {for (int k = 0; k <cct; k ++) {int nn = 0, ff = 1; (Int I = 1; ff & I <= n; I ++) for (int j = 1; ff & j <= n; j ++) if (c [k] [nn ++]! = B [I] [j]) {ff = 0; break;} if (ff) return 1;} return 0;} int main () {# ifdef test freopen ("sample.txt", "r", stdin); # endif int I, N, x [102], y [102]; char str [102]; while (scanf ("% d", & n), n) {int flag = 1; cct = num = 0; memset (a, '0 ', sizeof (a); for (I = 1; I <= n; I ++) a [I] [n + 1] = 0; N = 2 * n; for (I = 1; I <= N; I ++) scanf ("% d % c", & x [I], & y [I], & str [I]); for (I = 1; I <= N; I ++) {if (str [I] = '+ ') a [x [I] [y [I] = '1'; else a [x [I] [y [I] = '0 '; memcpy (B, a, sizeof (a); if (Search () break; Hash (); for (int j = 1; j <= n; j ++) for (int k = 1; k <= n; k ++) B [k] [n-j + 1] = a [j] [k]; if (Search () break; Hash (); for (int j = 1; j <= n; j ++) for (int k = 1; k <= n; k ++) B [n-k + 1] [j] = a [j] [k]; if (Search () break; Hash (); for (int j = 1; j <= n; j ++) for (int k = 1; k <= n; k ++) B [j] [n-k + 1] = a [j] [k]; if (Search () break; Hash (); cct = num ;} if (I % 2) flag = 2; if (I <= N) printf ("Player % d wins on move % d \ n", flag, I ); else puts ("Draw");} 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.