TJU ACM Problem【4157】
来源:互联网 发布:德州扑克 ev值 知乎 编辑:程序博客网 时间:2024/05/21 13:15
I have some pictures, some of them are same. And the colors are only black and white.So I want to make a chanllenge to you. You need to distinguish whether two pictures are same or not.Note that each picture can be rotated.Get more information from the sample.
Input
A number n(Output
Output 'Yes' if the two picture are same or 'No' otherwise.Sample Input
21111100000000000000000000100001000010000100001000010000100001000010000100000001000001000010000100001
Sample Output
YesNo
思路:将两个数组进行对比,若相等则输出Yes;若不相等,则将数组b顺时针旋转90度,在进行比对;重复步骤二3次,3次后没有比对成功则输出“No”
#include <iostream>#include <string>#include<cstdlib>using namespace std;int a[5][5];int b[5][5];void display(int c[5][5]){ int i,j; for(i=0;i<5;i++)//输入数组c for(j=0;j<5;j++) { if(j==4) cout<<c[i][j]<<endl; else cout<<c[i][j]<<" "; }}int is_equal()//判断数组是否相等{ int i,j; int flag=0; for(i=0;i<5;i++) { for(j=0;j<5;j++) { if(a[i][j]!=b[i][j]) { flag=1; break; } } if(flag==1) break; } if(flag==0) return 1;}void revenge()//将数组b顺时针转动{ int i,j,t; int m=2; for(i=0;i<=2;i++) { for(j=i;j<5-1-i;j++) { t=b[i][j]; b[i][j]=b[5-1-j][i]; b[5-1-j][i]=b[5-1-i][5-1-j]; b[5-1-i][5-1-j]=b[j][5-1-i]; b[j][5-1-i]=t; } }}int main(){ int n,i,j; cin>>n; while(n--) { for(i=0;i<5;i++)//输入数组a for(j=0;j<5;j++) { cin>>a[i][j]; } for(i=0;i<5;i++)//输入数组b for(j=0;j<5;j++) { cin>>b[i][j]; } if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第一次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第二次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } //第三次顺时针旋转 revenge(); if(is_equal()==1)//若数组a,b匹配成功 { cout<<"Yes"<<endl; continue; } cout<<"No"<<endl; } return 0;}
0 0
- TJU ACM Problem【4157】
- TJU ACM Problem 【4158】
- TJU Root of the Problem
- tju 4069 kai's problem (hash)
- TJU-4107. A simple problem(贪心)
- TJU ACM-ICPC Online Judge—1191 The Worm Turns
- Euclid Problem-ACM
- ACM Problem A
- ACM Problem B
- ACM Problem C
- [ACM]a+b problem
- [ACM]Sum Problem
- acm-A*B Problem
- acm-A-B Problem
- acm-A/B Problem
- acm-Train Problem I
- ACM-Train Problem I
- ACM Problem E
- 简历里的这些词,真的不能有!
- jQuery的属性与样式之html()及.text()
- string.h\cstring\string
- 安卓六大设计原则
- Lambda表达式和Java集合框架
- TJU ACM Problem【4157】
- 网络编程之服务端和客户端【Python版】
- 测试
- 实现Android Button边框色和主体色不同,定制自己想要的button样式
- JsonData
- 安全攻防——Objective-C代码混淆
- 粒子群算法几个适应度评价函数
- Oracle12C--Oracle事务处理(十一)
- sass 的基础应用 ruby