usaco-tranform:pass
这个题目是最简单的,虽然步数多了些,但它是最简单的,没怎么费脑力:
/*
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!
/***********************************************
看书看原版,原汁原味。
不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。
没有原书,也要网上找PDF来看。
网上的原版资料多了去了,下载东西也到原始下载点去看看。
你会知其所以然,呵呵。
***********************************************/