rt,刚刚在做P1213这道题,交上去 WA 了,下载数据来看本地跑答案是对的。问机房 dalao ,他说扔到洛谷 IDE 上跑,跑了一遍果然 WA 了,请问这是什么问题?
(有没有可能是 UB 导致啊?)
下面代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
//using namespace std;
inline int read(){
int x=0,fh=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-');
fh=-1;
ch=getchar();
}
while(isdigit(ch)){
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return x*fh;
}
int M[4][4];
signed main(){
for(int i=1;i<=3;++i)
for(int j=1;j<=3;++j)
M[i][j]=(read()/3)%4;
// for(int i=1;i<=3;++i)
// for(int j=1;j<=3;++j){
// printf("%d ",M[i][j]);
// if(j==3) puts("");
// }
for(int i1=0;i1<=3;++i1){
for(int i2=0;i2<=3;++i2){
for(int i3=0;i3<=3;++i3){
for(int i4=0;i4<=3;++i4){
for(int i5=0;i5<=3;++i5){
for(int i6=0;i6<=3;++i6){
for(int i7=0;i7<=3;++i7){
for(int i8=0;i8<=3;++i8){
for(int i9=0;i9<=3;++i9){
if(
(i1+i2+i4+M[1][1])%4==0
&& (i1+i2+i3+i5+M[1][2])%4==0
&& (i2+i3+i6+M[1][3])%4==0
&& (i1+i4+i5+i7+M[2][1])%4==0
&& (i1+i3+i5+i7+i9+M[2][2])%4==0
&& (i3+i5+i6+i9+M[2][3])%4==0
&& (i4+i7+i8+M[3][1])%4==0
&& (i5+i7+i8+i9+M[3][2])%4==0
&& (i6+i8+i9+M[3][3])%4==0
){
for(int i=1;i<=i1;++i)
printf("1 ");
for(int i=1;i<=i2;++i)
printf("2 ");
for(int i=1;i<=i3;++i)
printf("3 ");
for(int i=1;i<=i4;++i)
printf("4 ");
for(int i=1;i<=i5;++i)
printf("5 ");
for(int i=1;i<=i6;++i)
printf("6 ");
for(int i=1;i<=i7;++i)
printf("7 ");
for(int i=1;i<=i8;++i)
printf("8 ");
for(int i=1;i<=i9;++i)
printf("9 ");
}
}
}
}
}
}
}
}
}
}
return 0;
}