Kuangbin OJ 1217--Operations on Grids (YY) (Good question)

Source: Internet
Author: User

1217:operations on Grids time limit: 2 Sec Memory Limit: MB
Submit: Solved: 20
[Submit] [Status] [Web Board] Description

You have a 9-digit string, and now you have to fill in the 3x3 lattice with every bit of the number. If the number is 123456789, then fill in the 3x3 lattice to get: 123

456 789 Now you can do four things with this 3x3 lattice:

now give you this 9-bit number string, you need to do Left rotation operation,   Right rotation operation,   c    horizontal rollover operation,   The vertical flip operation, the sequence between these operations you decide.   asked how many different 3x3 squares can be obtained. Two 3x3 lattices are considered different when and only if there is at least one position in the   lattice.



Input

Enter the first line is an integerT t    each group of data has two rows. The first behavior is a 9-bit number string. The second line consists of 4 integers   a b C   (0 <=  a ,   b C D   <= 2)


Output

For each set of test data, the output of an integer indicates how many different 3x3 squares can eventually be obtained.


Sample Input
10000000001 2 1 2
Sample Output
1
HINT


train of thought: Because A,b,c,d is small, direct Dfs also can, but more yy also quite happy
yy After the conclusion:

C,d's only role is to:1. If C,d is 0, then the solution is only one case2.c,d One of them is not 0 .when the turn face, a actually turn right, b actually turn left, so, when c,d a not for 0 can let a, b contribute to each other, how much contribution (not more than a A, a self) only depends on and when to turn the face

when the figure is up or down symmetrical then the solution is 1
when the center of the graph is symmetrical then left 2 times and 4 times the same
In These three cases:
1312 KB 0 msc++ 1491 B 2015-03-21 23:04:38#include<cstdio> #include <iostream> #include <algorithm>#    Include<cstring>using namespace Std;char num[15];bool vis[5];int main () {int T;    scanf ("%d", &t);        while (t--) {int ans=0;        BOOL flag=0;        memset (vis,0,sizeof (VIS));        scanf ("%s", num+1);        int a,b,c,d;        scanf ("%d%d%d%d", &a,&b,&c,&d); if (num[1]==num[3]&&num[7]&&num[9]&&num[3]==num[7]&&num[2]==num[4]&&num            [4]==num[6]&&num[6]==num[8]) {printf ("1\n");        Continue            } if (c==0&&d==0) {printf ("1\n");        Continue        } if (num[4]==num[6]&&num[2]==num[8]&&num[1]==num[9]&&num[3]==num[7]) flag=1;        int s=a-b;            if (!vis[(s+4)%4]) {ans++;            vis[(s+4)%4] = true;        if (flag) vis[(s+2)%4] =true; } for (int i=1;i<=b;i++) {s+=2;            if (!vis[(s+4)%4]) ans++;            vis[(s+4)%4] = true;        if (flag) vis[(s+2)%4]=true;        } s=a-b;            for (int i=1;i<=a;i++) {s-=2;            if (!vis[(s+8)%4]) ans++;            vis[(s+8)%4]=true;        if (flag) vis[(s+10)%4]=true;    } printf ("%d\n", ans); } return 0;}



Kuangbin OJ 1217--Operations on Grids (YY) (Good question)

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.