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

    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
    
    破题 真麻烦 给你一个字符矩形 在给你一个字符矩形 问用上述的哪种转换可以把第一个变成第二个 输出最小的转换编号
    View Code
      1 /*
      2  ID: your_id_here
      3  LANG: C++
      4  TASK: transform
      5  */
      6 #include <iostream>
      7 #include<cstdio>
      8 #include<string.h>
      9 using namespace std;
     10 int n;
     11 int judge(char s[][11],char x[][11])
     12 {
     13     int flag = 1,i,j;
     14     for(i = 1; i <= n ; i++)
     15     {
     16         for(j = 1; j <= n ; j++)
     17         {
     18             if(s[i][j]!=x[i][j])
     19             {
     20                 flag = 0;
     21                 break;
     22             }
     23         }
     24         if(!flag)
     25         break;
     26     }
     27     return flag;
     28 }
     29 int main()
     30 {
     31     freopen("transform.in","r",stdin);
     32     freopen("transform.out","w",stdout);
     33     int i,j,m,flag,k;
     34     char c[11][11],s[11][11],x[7][11][11];
     35     scanf("%d",&n);
     36     for(i = 1; i <= n ; i++)
     37     {
     38         getchar();
     39         for(j = 1; j <= n ; j++)
     40         c[i][j] = getchar();
     41     }
     42     for(i = 1; i <= n ; i++)
     43     {
     44         getchar();
     45         for(j = 1; j <= n ; j++)
     46         s[i][j] = getchar();
     47     }
     48     for(i = 1 ; i <= n ; i++)
     49     for(j = 1; j <= n ; j++)
     50     {
     51         x[0][i][j] = c[n+1-j][i];
     52         x[1][i][j] = c[n+1-i][n+1-j];
     53         x[2][i][j] = c[j][n+1-i];
     54         x[3][i][j] = c[i][1+n-j];
     55     }
     56     if(judge(s,x[0]))
     57     {
     58         printf("1\n");
     59     }
     60     else
     61     if(judge(s,x[1]))
     62     printf("2\n");
     63     else
     64     if(judge(s,x[2]))
     65     printf("3\n");
     66     else
     67     if(judge(s,x[3]))
     68     printf("4\n");
     69     else
     70     {
     71         for(i = 1 ; i <= n ; i++)
     72         for(j = 1; j <= n ; j++)
     73         x[4][i][j] = x[3][n+1-j][i];
     74         if(judge(s,x[4]))
     75         printf("5\n");
     76         else
     77         {
     78             for(i = 1 ; i <= n ; i++)
     79             for(j = 1; j <= n ; j++)
     80             x[4][i][j] = x[3][n+1-i][n+1-j];
     81             if(judge(s,x[4]))
     82             printf("5\n");
     83             else
     84             {
     85                  for(i = 1 ; i <= n ; i++)
     86                  for(j = 1; j <= n ; j++)
     87                  x[4][i][j] = x[3][j][n+1-i];
     88                  if(judge(s,x[4]))
     89                  printf("5\n");
     90                  else
     91                  if(judge(s,c))
     92                  {
     93                      printf("6\n");
     94                  }
     95                  else
     96                  printf("7\n");
     97             }
     98         }
     99     }
    100     fclose(stdin);
    101     fclose(stdout);
    102     return 0;
    103 }
  • 相关阅读:
    Apache Hive (三)Hive元数据信息对应MySQL数据库表
    Apache Hive (二)Hive安装
    Apache Hive (一)Hive初识
    C#使用NPOI导出excel设置单元格背景颜色
    Spark之 Spark Streaming整合kafka(并演示reduceByKeyAndWindow、updateStateByKey算子使用)
    Spark之 Spark Streaming流式处理
    Apache Flume的介绍安装及简单案例
    Kafka如何保证数据不丢失
    Ajax
    HttpComponents
  • 原文地址:https://www.cnblogs.com/shangyu/p/2649742.html
Copyright © 2011-2022 走看看