USACO--Transformations

来源:互联网 发布:拦截广告软件 编辑:程序博客网 时间:2024/05/18 03:31

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, NLine 2..N+1:N lines of N characters (each either `@' or `-'); this is the square before transformationLine 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


我先说我的思路: 我就是先把图形进行题目要求中的操作进行旋转,如果条件满足,就输出操作数,并结束程序,结果 return 0用的好多啊=_=

下边是代码:

/*ID:lk951201PROB:transformLANG:C++*/#include<iostream>#include<cstdio>#include<cstring>#define MAXN 105#define pf printfusing namespace std;int N;char bef[MAXN][MAXN];   //bef数组用于存放最开始的图形char mid[MAXN][MAXN];   //mid数组用于存放旋转的图形char aft[MAXN][MAXN];   //aft数组存放最后的图形bool is_equal()  //判断图形是不是相同{    bool ok=true;    for(int i=0;i<N;i++)    {        if(strcmp(bef[i],aft[i]) ) {ok=false;break;}   //采用每一行比较的方式    }    return ok;}void copytobef()     //因为把顺时针旋转过的图形放在了mid数组中,在复制回来,以方便上边的判断图形是否相同{    for(int i=0;i<N;i++)    {        strcpy(bef[i],mid[i]); //和上边一样,一行一行的复制    }}void trans_x()   //对图形进行X镜像翻转{    for(int i=0;i<N;i++)    {        int n=N-1;        for(int j=0;j<=n;j++)        {            char t=bef[i][j];            bef[i][j]=bef[i][n];            bef[i][n]=t;            n--;        }    }}void clockwize()     //对图形进行顺时针旋转,把旋转过的放到mid输注中{    int n=N-1;    for(int i=0;i<N;i++)    {        for(int j=0;j<N;j++)        {            mid[j][n]=bef[i][j];        }        n--;    }}int main(){    freopen("transform.in","r",stdin);    freopen("transform.out","w",stdout);    memset(bef,0,sizeof(bef));     //数组进行清空    memset(mid,0,sizeof(mid));    memset(aft,0,sizeof(aft));    scanf("%d",&N);    for(int i=0;i<N;i++)        scanf("%s",bef[i]);    for(int i=0;i<N;i++)        scanf("%s",aft[i]);    clockwize();copytobef();   //第一次进行顺时针旋转,旋转过后在mid数组中,因为判断是在bef中,所以在复制到bef中    if(is_equal()) {pf("1\n");return 0;} //如果图形一样,输出1,并结束    clockwize();copytobef();   //第二次旋转    if(is_equal()) {pf("2\n");return 0;}    clockwize();copytobef();   //第三次旋转    if(is_equal()) {pf("3\n");return 0;}    clockwize();copytobef();trans_x();  //旋转四次,就恢复成原图形,这时候再进行X镜像旋转    if(is_equal()) {pf("4\n");return 0;} //如果图形相同,~    clockwize();copytobef();            //因为已经X镜像旋转过,所以依次旋转1次,判断    if(is_equal()) {pf("5\n");return 0;}    clockwize();copytobef();            //两次    if(is_equal()) {pf("5\n");return 0;}    clockwize();copytobef();            //三次    if(is_equal()) {pf("5\n");return 0;}    clockwize();copytobef();            //如果x旋转过后,在旋转1,2,3次后还不满足,再旋转一次,成最初的图形    if(is_equal()) {pf("6\n");return 0;} //判断,为什么不开始就判断呢?因为如果都满足,先输出小的    printf("7\n");return 0;  // 都不满足,只能输出7了}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 蚂蚱没有草吃了怎么办 笔记本电源已接通未充电怎么办 电源已接通未充电怎么办 遮盖纹身好了颜色淡了怎么办 致炫方向盘变重怎么办 xp音频图标没了怎么办 狙击精英3没子弹怎么办 干活干的手腕疼怎么办 干了活不给钱怎么办 干了活要不到钱怎么办 活干完了钱不给怎么办 微信语音聊天音量很小怎么办 一手软件崩溃钱卡住了怎么办 身上皮肤很黑怎么办?好想穿短裙 家里有很多小飞虫怎么办 家里有垃圾中飞出虫子怎么办 雷蛇笔记本很烫怎么办 登录监控器的账号锁了怎么办 悦借钱登录账号被锁怎么办 365账号登录被锁怎么办 台式电脑cpu温度过高怎么办 UG2.0打不开错误—15怎么办 键盘空格键删除键失灵怎么办 耳麦检测声音不分左右怎么办 吃生萝卜胃疼怎么办 幼兔拉稀怎么办没精神 自酿米酒酸了怎么办 用冰敷脸感觉红烫了怎么办 吃了海兔的内脏怎么办 吃了鱿鱼的吸盘怎么办 想开个烧烤店没学过怎么办 墨鱼汁弄衣服上怎么办 干鱿鱼泡开发黄怎么办 吃了芥末胃疼怎么办 手撕鱿鱼咸了怎么办 孕妇吃了点芥末怎么办 葡萄酒上面有一层白霉怎么办 手机一不小心把视频删了怎么办 柑橘7月份果实小怎么办 鹦鹉鱼身上有小白点怎么办 鹦鹉鱼身上烂了怎么办