码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-tranform:pass

时间:2014-08-29 15:50:18      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   数据   div   

这个题目是最简单的,虽然步数多了些,但它是最简单的,没怎么费脑力:

/*
ID: qq104801
LANG: C++
TASK: transform
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/* for debug only:counter
*/
void debug_dummy(void)
{
    return;
}

const int MAX=10;
typedef struct _kk
{
    char x[MAX][MAX];
}kk,*pkk;

int n;
kk a,b,t,t1,t2;

void rotate(kk* src,kk* tar)
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            tar->x[i][j]=src->x[n-j-1][i];    
}

void rotate1()
{
    rotate(&a,&t);
}

void rotate2()
{
    rotate(&a,&t2);
    rotate(&t2,&t);
}

void rotate3()
{
    rotate(&a,&t);
    rotate(&t,&t2);
    rotate(&t2,&t);
}

void mirror()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            t.x[i][j]=a.x[i][n-1-j]; 
}

int cmp(kk* src,kk* tar)
{
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if (tar->x[i][j]!=src->x[i][j])
                return 0;
    return 1;
}

int trans()
{
    
    rotate1();if (cmp(&b,&t))return 1;
    rotate2();if (cmp(&b,&t))return 2;    
    rotate3();if (cmp(&b,&t))return 3;
    mirror();if (cmp(&b,&t))return 4;
    rotate(&t,&t1);if(cmp(&b,&t1))return 5;
    rotate(&t1,&t);if(cmp(&b,&t))return 5;
    rotate(&t,&t1);if(cmp(&b,&t1))return 5;
    if (cmp(&a,&b))return 6;
    return 7;
}

void test()
{
    printf("%d\n",n);
    printf("a:\n");
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)            
            printf("%c",a.x[i][j]);        
        printf("\n");
    }
    printf("b:\n");
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)            
            printf("%c",b.x[i][j]);        
        printf("\n");
    }
    printf("t:\n");
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)            
            printf("%c",t.x[i][j]);        
        printf("\n");
    }
}


main () {    
    FILE *fin = fopen ("transform.in", "r");
    FILE *fout = fopen ("transform.out", "w"); 
    fscanf(fin,"%d",&n);
    assert(getc(fin)==\n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            a.x[i][j]=getc(fin);
        assert(getc(fin)==\n);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            b.x[i][j]=getc(fin);
        assert(getc(fin)==\n);
    }    
    
    int b;
    b=trans();
    fprintf(fout,"%d\n",b);
    //printf("%d\n\n",b);
    //test();
    fclose(fin);
    fclose(fout);
    exit (0);
}

看下测试数据用例:

ll tom [qq104801]
TASK: transform
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.011 secs, 3520 KB]
   Test 2: TEST OK [0.003 secs, 3520 KB]
   Test 3: TEST OK [0.008 secs, 3520 KB]
   Test 4: TEST OK [0.014 secs, 3520 KB]
   Test 5: TEST OK [0.008 secs, 3520 KB]
   Test 6: TEST OK [0.016 secs, 3520 KB]
   Test 7: TEST OK [0.008 secs, 3520 KB]
   Test 8: TEST OK [0.005 secs, 3520 KB]

All tests OK.

Your program (‘transform‘) produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
3
---
---
---
---
-@-
---
------- test 2 ----
5
-@@@-
-@@--
-@---
-----
-----
-----
----@
---@@
--@@@
-----
------- test 3 ----
5
@@@@@
@---@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
@---@
@@@@@
------- test 4 ----
6
-@-@-@
@-@-@-
-@-@-@
@-@-@-
-@-@-@
@-@-@-
@-@-@-
-@-@-@
@-@-@-
-@-@-@
@-@-@-
-@-@-@
------- test 5 ----
3
@@@
---
@@@
@@@
---
@@@
------- test 6 ----
4
@@@@
@@@@
-@@@
@@@@
@@@@
@@@@
@@@-
@@@@
------- test 7 ----
4
@-@@
@@@@
@@@@
@@@@
@@@@
@@@@
@@@@
@-@@
------- test 8 ----
10
@--------@
----------
----------
----------
----------
----------
----------
----------
----------
----------
@---------
----------
----------
----------
----------
----------
----------
----------
----------
---------@

Keep up the good work!
Thanks for your submission!

 

usaco-tranform:pass

标签:style   blog   color   os   io   ar   for   数据   div   

原文地址:http://www.cnblogs.com/dpblue/p/3944999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!