usaco-tranform:pass

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   ar   for   資料   div   

這個題目是最簡單的,雖然步數多了些,但它是最簡單的,沒怎麼費腦力:

/*ID: qq104801LANG: 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: transformLANG: C++Compiling...Compile: OKExecuting...   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------------[email protected]---------- test 2 ----5[email protected]@@-[email protected]@--[email protected]-------------------@---@@--@@@------------ test 3 ----5@@@@@@---@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@---@@@@@@------- test 4 ----6[email protected]@-@@[email protected]@-[email protected]@-@@[email protected]@-[email protected]@-@@[email protected]@-@[email protected]@-[email protected]@-@@[email protected]@-[email protected]@-@@[email protected]@-[email protected]@-@------- test 5 ----3@@@---@@@@@@---@@@------- test 6 ----4@@@@@@@@-@@@@@@@@@@@@@@@@@@-@@@@------- test 7 ----4@-@@@@@@@@@@@@@@@@@@@@@@@@@@@-@@------- test 8 ----10@--------@------------------------------------------------------------------------------------------@--------------------------------------------------------------------------------------------------@Keep up the good work!Thanks for your submission!

 

usaco-tranform:pass

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.