zoukankan      html  css  js  c++  java
  • USACO1.2.2Transformations

    Transformations

    A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

    • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
    • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
    • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
    • #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
    • #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
    • #6: No Change: The original pattern was not changed.
    • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

    In the case that more than one transform could have been used, choose the one with the minimum number above.

    PROGRAM NAME: transform

    INPUT FORMAT

    Line 1: A single integer, N
    Line 2..N+1: N lines of N characters (each either `@' or `-'); this is the square before transformation
    Line N+2..2*N+1: N lines of N characters (each either `@' or `-'); this is the square after transformation

    SAMPLE INPUT (file transform.in)

    3
    @-@
    ---
    @@-
    @-@
    @--
    --@
    

    OUTPUT FORMAT

    A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.

    SAMPLE OUTPUT (file transform.out)

    1
    题解:a数组是转换前的状态,b数组是转换后的状态。
    只要枚举这七种情况即可
    顺时针转90度:b[i][j]=a[n-j-1][i];
    顺时针转180度:b[i][j]=a[n-i-1][n-j-1];
    顺时针转270度:b[i][j]=a[j][n-i-1];
    水平翻转:b[i][j]=a[i][n-j-1];
    第五种情况的话,先把b水平翻转一下,然后再判断是否符合1-3中的一种。
    不改变:b[i][j]=a[i][j];
    如果以上六种情况都不符合,那就直接输出7就OK了。。。
    View Code
      1 /*
      2 ID:spcjv51
      3 PROG:transform
      4 LANG:C
      5 */
      6 #include<stdio.h>
      7 #include<string.h>
      8 #define maxn 11
      9 char a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
     10 int n;
     11 int trans1()
     12 {
     13     int i,j;
     14     for(i=0; i<n; i++)
     15         for(j=0; j<n; j++)
     16             if(b[i][j]!=a[n-j-1][i]) return 0;
     17     return 1;
     18 }
     19 int trans2()
     20 {
     21     int i,j;
     22     for(i=0; i<n; i++)
     23         for(j=0; j<n; j++)
     24             if(b[i][j]!=a[n-i-1][n-j-1]) return 0;
     25     return 1;
     26 
     27 }
     28 int trans3()
     29 {
     30     int i,j;
     31     for(i=0; i<n; i++)
     32         for(j=0; j<n; j++)
     33             if(b[i][j]!=a[j][n-i-1]) return 0;
     34     return 1;
     35 }
     36 int trans4()
     37 {
     38     int i,j;
     39     for(i=0; i<n; i++)
     40         for(j=0; j<n; j++)
     41             if(b[i][j]!=a[i][n-j-1]) return 0;
     42     return 1;
     43 }
     44 int trans6()
     45 {
     46     int i,j;
     47     for(i=0; i<n; i++)
     48         for(j=0; j<n; j++)
     49             if(b[i][j]!=a[i][j]) return 0;
     50     return 1;
     51 }
     52 
     53 int main(void)
     54 {
     55     freopen("transform.in","r",stdin);
     56     freopen("transform.out","w",stdout);
     57     int i,j,m,ans,flag;
     58     scanf("%d",&n);
     59     for(i=0; i<n; i++)
     60         scanf("%s",a[i]);
     61     for(i=0; i<n; i++)
     62         scanf("%s",b[i]);
     63     flag=1;
     64     if(flag&&trans1())
     65     {
     66         printf("1\n");
     67         flag=0;
     68     }
     69     if(flag&&trans2())
     70     {
     71         printf("2\n");
     72         flag=0;
     73     }
     74     if(flag&&trans3())
     75     {
     76         printf("3\n");
     77         flag=0;
     78     }
     79     if(flag&&trans4())
     80     {
     81         printf("4\n");
     82         flag=0;
     83     }
     84     if(flag)
     85     {
     86         int i,j;
     87         for(i=0; i<n; i++)
     88             for(j=0; j<n; j++)
     89                 c[i][j]=b[i][n-j-1];
     90         for(i=0; i<n; i++)
     91             for(j=0;j<n;j++)
     92                 b[i][j]=c[i][j];
     93         if(trans1()||trans2()||trans3())
     94         {
     95             printf("5\n");
     96             flag=0;
     97         }
     98     }
     99 
    100     if(flag&&trans6())
    101     {
    102         printf("6\n");
    103         flag=0;
    104     }
    105     if(flag) printf("7\n");
    106     return 0;
    107 }
    
    
    




  • 相关阅读:
    DQL:data query language用来查询数据库表中的数据
    Mysql训练:两个表中使用 Select 语句会导致产生 笛卡尔乘积 ,两个表的前后顺序决定查询之后的表顺序
    最常用SQL joins:内连接(交集)、左外连接、右外连接、左连接、右连接、全连接(并集),全外连接
    空间异常即刻诊断,华为云数据管理服务DAS又出新招~
    【华为云技术分享】【论文阅读】增量式物体检测
    【华为云技术分享】如何让敏捷回顾会议更有效果,这样做就对了
    【华为云技术分享】如何处理暗数据?
    【华为云技术分享】MongoDB经典故障系列五:sharding集群执行sh.stopBalancer()命令被卡住怎么办?
    【华为云技术分享】云图说 | 初识云耀云服务器,打造“极优、极简”的云上体验
    【华为云技术分享】十分钟从入门到精通(上)—对象存储服务的OBS权限配置
  • 原文地址:https://www.cnblogs.com/zjbztianya/p/2858812.html
Copyright © 2011-2022 走看看