Usaco Section1.2 Transformations Problem Solving report

Source: Internet
Author: User

Transform Problem solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
The matrix A and B of two nxn are given, and the output number of the lowest number in the way of converting A to B is found.
#1: Turn 90 degrees: The pattern is rotated clockwise by 90 degrees.
#2: Turn 180 degrees: The pattern is rotated clockwise by 180 degrees.
#3: Turn 270 degrees: The pattern is rotated clockwise by 270 degrees.
#4: Reflection: The pattern flips horizontally (mirrors that form the original pattern).
#5: Mix: The pattern flips horizontally and then follows the #1-#3之一转换.
#6: Do not change: The original pattern does not change.
#7: Invalid conversion: The new pattern cannot be obtained with the above method.
"Data Range"
1<=n<=10
In the matrix, there are only two characters: @ or-(personally, I think it's useless, perhaps to save some input and output judgment)
"Input Sample"
3
@[email protected]
---
@@-
@[email protected]
@--
[Email protected]
"Output Example"
1
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
Direct simulation, take care not to reverse the good (personal advice to print out to see).
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
I turned to the opposite ...
There is a place to note, that is, turn 180 degrees, the first reaction probably is directly with the last turn 90 degrees of the results continue to turn, but do not forget that if in situ turn (in the same matrix relay, not to apply for new space) is bound to be wrong-.-

--------------------------------------------------------------------------------------------------------------- ---------------------------------

Code

1 /*2 id:icedrea13 Prob:transform4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten  One intN; AtypedefCharmap[Ten+1][Ten+1]; - Map A, b; -  the voidPP (Map x) - { -      for(intI=0; i!=n;++i) -     { +          for(intj=0; j!=n;++j) cout<<X[i][j]; -cout<<Endl; +     } Acout<<"------------------------------------"<<Endl; at } - void Get(Map x,map y) - { -      for(intI=0; i!=n;++i) -          for(intj=0; j!=n;++j) x[i][j]=Y[i][j]; - } in BOOLSame (Map X,map y) - { to      for(intI=0; i!=n;++i) +          for(intj=0; j!=n;++j) -             if(X[i][j]!=y[i][j])return false; the     return true; * } $ intWork ()Panax Notoginseng { - Map t,k; the  + PP (A); PP (B); A  the     //#1 (i,j) = (n-1-j,i) +     Get(k,a); -      for(intI=0; i!=n;++i) $          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; $ PP (t); -     if(Same (T,B))return 1; -  the     //#2 #1 x2 -     Get(k,t);Wuyi      for(intI=0; i!=n;++i) the          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; - PP (t); Wu     if(Same (T,B))return 2; -  About     //#3 #1 X3 $     Get(k,t); -      for(intI=0; i!=n;++i) -          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; -     if(Same (T,B))return 3; A  +     //#4 (i,j) = (i,n-1-j) the     Get(k,a); -      for(intI=0; i!=n;++i) $          for(intj=0; j!=n;++j) t[i][j]=k[i][n-1-j]; the     if(Same (T,B))return 4; the  the     //#5 #4 + #1 ~ the     Get(k,t); -      for(intI=0; i!=n;++i) in          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; the     if(Same (T,B))return 5; the     Get(k,t); About      for(intI=0; i!=n;++i) the          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; the     if(Same (T,B))return 5; the     Get(k,t); +      for(intI=0; i!=n;++i) -          for(intj=0; j!=n;++j) t[i][j]=k[n-1-J] [i]; the     if(Same (T,B))return 5;Bayi  the     //#6 No change the     if(Same (A, b))return 6; -  -     //#7 Impossible the     return 7; the } the  the intMain () - { theIfstreaminch("transform.in"); theOfstream out("Transform.out"); the 94     inch>>N;inch.Get(); the      for(intI=0; i!=n;++i) the     { the          for(intj=0; j!=n;++j) a[i][j]=inch.Get();98         inch.Get(); About     } -      for(intI=0; i!=n;++i)101     {102          for(intj=0; j!=n;++j) b[i][j]=inch.Get();103         inch.Get();104     } the 106      out<<work () <<Endl;107 108     inch. Close ();109      out. Close (); the     return 0;111}

Usaco Section1.2 Transformations Problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.