USACO之Section1.2.2 Transformations[模拟]
来源:互联网 发布:淘宝贷款逾期無法再借 编辑:程序博客网 时间:2024/05/19 19:14
这道题用模拟的方法。
做题时有一些小细节需要注意,可以优化代码。
首先判断6这种情况,然后再依次判断1-5的情况,其中2,3种情况建立在第1种情况上。
具体代码如下:
/* ID:m1519591 PROG: transform LANG:C++*/#include<iostream>#include<fstream>using namespace std;const int size = 11;char st[size][size];char en[size][size];int ans=7;int n;void Deg90(){ char tmp[size][size]; for(int i=0;i<=n-1;i++) { for(int j=0;j<=n-1;j++) tmp[j][n-i-1]=st[i][j]; } for(int i=0;i<=n-1;i++) { for(int j=0;j<=n-1;j++) st[i][j]=tmp[i][j]; }}void Ref(){ char tmp[size][size]; for(int i=0;i<=n-1;i++) { for(int j=0;j<=n-1;j++) tmp[i][n-j-1]=st[i][j]; } for(int i=0;i<=n-1;i++) { for(int j=0;j<=n-1;j++) st[i][j]=tmp[i][j]; }}void Comp(int x){ bool flag =true; for(int i=0;i<=n-1;i++) { for(int j=0;j<=n-1;j++) { if(st[i][j]!=en[i][j]) { flag=false; break; } } } if(flag) ans=min(ans,x);}int main(){ ofstream cout("transform.out"); ifstream cin("transform.in"); cin>>n; for(int i=0;i<=n-1;i++) cin>>st[i]; for(int i=0;i<=n-1;i++) cin>>en[i]; Comp(6); Deg90(); Comp(1); if(ans==1) cout<<ans<<endl; else { Deg90(); Comp(2); if(ans==2) cout<<ans<<endl; else { Deg90(); Comp(3); if(ans==3) cout<<ans<<endl; else{ Deg90(); Ref(); Comp(4); if(ans==4) cout<<ans<<endl; else { for(int i=0;i<=2;i++) { Deg90(); Comp(5); if(ans==5) { cout<<ans<<endl; break; } } if(ans!=5) cout<<ans<<endl; } } } } return 0;}
阅读全文
0 0
- USACO之Section1.2.2 Transformations[模拟]
- USACO Section1.2 Transformations
- USACO-Section1.2 Transformations
- usaco section1.2 Transformations
- USACO Section1.2 Transformations
- USACO-Section1.2 Transformations
- USACO-Section1.2 Transformations [其他]
- USACO-Section1.2 Transformations【数论.矩阵旋转】
- USACO 1.2 Transformations(模拟)
- 【USACO-Chapter1-1.2】【模拟】Transformations
- usaco 1.2 Transformations(模拟)
- USACO 1.2 Transformations (模拟)
- Transformations(模拟)(USACO)
- usaco Transformations 模拟模拟模拟 ,惨不忍睹
- USACO-section1.2.2 transform
- USACO 1.2.2 Transformations(模拟)
- usaco Transformations (矩形翻转||模拟题)
- usaco.section1.3.Combination Lock(暴力模拟)
- phpcms模板
- Swift-枚举的基本学习和高级使用
- OpenMP Atomic
- 数组中找重复的数字
- 强化学习笔记04——动态规划
- USACO之Section1.2.2 Transformations[模拟]
- 算法导论——栈与队列
- 职责链模式
- bzoj 1043 [HAOI2008]下落的圆盘
- 计算机组成原理——系统总线
- YUV数据格式
- JAVA中的集合类接口——Collection
- OpenMP threadprivate
- JNI字段描述符“([Ljava/lang/String;)V”