【USACO】Transformations(模拟)

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
@[email protected]
---
@@-
@[email protected]
@--
[email protected]

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

遇到了小问题,就是本地和USACO结果不一样,原来是少了句return。

/*
USER: RAO WENJIN
TASK: transform
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 15
using namespace std;
char s[2][N][N];
int n,op;
void rot(char s[][N],int times){
    char t[N][N];
    memset(t,0,sizeof t);
    for(int i=1;i<=times;i++){
	for(int i=0;i<n;i++)
	    for(int j=0;j<n;j++)
		t[j][n-i-1]=s[i][j];
	memcpy(s,t,sizeof t);
    }
}
void refl(char s[][N]){
    for(int i=0;i<n;i++)
        for(int j=0;j<n/2;j++)
            swap(s[i][n-j-1],s[i][j]);
}
int ck(){
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(s[1][i][j]!=s[0][i][j])return 0;
    return 1;
}
int work(int op){
    if(op==1)rot(s[0],1);
    if(op==2)rot(s[0],1);
    if(op==3)rot(s[0],1);
    if(op==4)rot(s[0],1),refl(s[0]);
    if(op==5){
        for(int i=0;i<3;i++){
            rot(s[0],1);
            if(ck())return 1;
        }
        return 0;//这句漏了
    }else return ck();
}
int main(){
    freopen("transform.in","r",stdin);
    freopen("transform.out","w",stdout);
    cin>>n;
    for(int k=0;k<2;k++)
    for(int i=0;i<n;i++)
        cin>>s[k][i];
    for(op=1;op<7;op++)
    if(work(op)){cout<<op<<endl;break;}
    if(op==7)cout<<7<<endl;
}
时间: 2024-08-04 13:35:19

【USACO】Transformations(模拟)的相关文章

USACO 1.2 Transformations (模拟)

模拟题目,按照题目给定的要求变换图形即可,变换的优先级依次减小.这个题目我写的很乱.不过最还还是勉强可以运行 /* ID:twd30651 PROG:transform LANG:C++ */ #include<iostream> #include<fstream> #include<stdlib.h> #include<string.h> using namespace std; #define MAX 10 char a[MAX][MAX]; char

Milking Cows 挤牛奶 USACO 排序 模拟

1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1.2.1 Milking Cows 挤牛奶 (milk2.pas/c/cpp) 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开始2100秒结束.期间最长的至

usaco Transformations

/* ID: modengd1 PROG: transform LANG: C++ */ #include <iostream> #include <stdio.h> using namespace std; char input1[10][10],input2[10][10]; char temp[10][10]; int N; bool isSame(char from[10][10],char to[10][10],int n) { for(int i=0;i<n;i+

【USACO】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 l

USACO 1.2 Transformations

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

USACO Section1.2 Transformations 解题报告

transform解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 给出两个N×N的矩阵A和B,找出将A转换为B的方式中编号最小的,输出编号. #1:转90度:图案按顺时针转90度. #2:

USACO Runaround Numbers 模拟

根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream>

USACO The Tamworth Two 模拟

一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留. 还是蛮简单的. 调试输出的话可以看到具体追击过程 Source Code: /* ID: wushuai2 PROG: ttwo LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include &

USACO Wormholes(模拟)

题目请点我 题解: 这道题思路很简单,就是简单的深搜,找出所有的组合,然后判断能否成环.关键在于如何判断能否成环,我的思路是利用递归模拟,看能否第二次经过某一个点.中间也出现了错误,首先,每次访问的下一个点应该是同一行上当前点右边的第一个点:其次,某个点被访问过必须是作为起点被访问过,而不仅仅是到达. 代码实现: /* ID: eashion LANG: C++ TASK: wormhole */ #include <iostream> #include <cstdio> #inc