文章
3
粉丝
274
获赞
访问
39.4k
1 多组输入输出,我一开始没有处理,只能通过50%,然而 北航的前面素数那道题,我也没有处理,竟然过了百分百;
2 旋转的时候记得 如果你只是设置了三个矩阵,一个作为旋转后的矩阵来做这道题的话,记得旋转90°之后,要更新之前用于选择的矩阵
# include <bits/stdc++.h> using namespace std;
int main(){ int n; while( cin>>n){ int a[n][n] ; int b[n][n] ; int a1[n][n] ; int a2[n][n] ; int a3[n][n] ; //a的输入 for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ cin>>a[i][j]; } } //b的输入 for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ cin>>b[i][j]; } }
//90 for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ a1[j][n-i+1] = a[i][j]; }}
for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ a2[j][n-i+1] = a1[i][j]; }} for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ a3[j][n-i+1] = a2[i][j]; }} bool flag1; for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ if (b[i][j] == a[i][j]) flag1 = true; else { flag1 = false; break; } } } bool flag2; for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ if (b[i][j] == a1[i][j]) flag2 = true; else { flag2 = false; break; } } } bool flag3; for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ if (b[i][j] == a2[i][j]) flag3 = true; else { flag3 = false; break; } } } bool flag4; for (int i =1; i<=n ; i++){ for (int j =1; j<=n ; j++){ if (b[i][j] == a3[i][j]) flag4 = true; else { flag4 = false; break; } } } if (flag1) {cout<<0<<endl;flag2=false;flag3=false;flag4=false;} if (flag2) {cout<<90<<endl;flag3=false;flag4=false;} if (flag3) {cout<<180<<endl;flag4=false;} if (flag4) cout<<270<<endl; if (flag1 == false && flag2 == false && flag3 == false && flag4 == false) cout << -1<<endl;
} return 0; }
为啥
dnn_yyds : 回复 dnn_yyds: 为啥我的成功率一直是80%,不知道哪里错了,呜呜呜。
补充一个坑,就是如果判断完是0度之后不能再去旋转矩阵了,我就是因为这样然后一直百分之五十,看了博主的代码后才改过来
我设置了两组输入啊,为什么还是只能通过50%啊,,很迷
wxq : 回复 983103231: while(scanf("%d", &n) != EOF){ //在这个while循环里面处理一个测试点 }
okk
登录后发布评论
# include <bits/stdc++.h>
using namespace std;
int main(){
int n;
while( cin>>n){
int a[n][n] ;
int b[n][n] ;
int a1[n][n] ;
int a2[n][n] ;
int a3[n][n] ;
//a的输入
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
cin>>a[i][j];
}
}
//b的输入
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
cin>>b[i][j];
}
}
//90
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
a1[j][n-i+1] = a[i][j];
}}
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
a2[j][n-i+1] = a1[i][j];
}}
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
a3[j][n-i+1] = a2[i][j];
}}
bool flag1;
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
if (b[i][j] == a[i][j])
flag1 = true;
else {
flag1 = false;
break;
}
}
}
bool flag2;
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
if (b[i][j] == a1[i][j])
flag2 = true;
else {
flag2 = false;
break;
}
}
}
bool flag3;
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
if (b[i][j] == a2[i][j])
flag3 = true;
else {
flag3 = false;
break;
}
}
}
bool flag4;
for (int i =1; i<=n ; i++){
for (int j =1; j<=n ; j++){
if (b[i][j] == a3[i][j])
flag4 = true;
else {
flag4 = false;
break;
}
}
}
if (flag1) {cout<<0<<endl;flag2=false;flag3=false;flag4=false;}
if (flag2) {cout<<90<<endl;flag3=false;flag4=false;}
if (flag3) {cout<<180<<endl;flag4=false;}
if (flag4) cout<<270<<endl;
if (flag1 == false && flag2 == false && flag3 == false && flag4 == false) cout << -1<<endl;
}
return 0;
}
为啥
补充一个坑,就是如果判断完是0度之后不能再去旋转矩阵了,我就是因为这样然后一直百分之五十,看了博主的代码后才改过来
我设置了两组输入啊,为什么还是只能通过50%啊,,很迷
okk