cygnus_beta @ 2021-05-30 11:52:41
该输出no的时候啥都没有,bool变量神奇地变成了true 代码如下:
#include<iostream>
#include<cstring>
using namespace std;
int gcd(const int a,const int b){
if(!b)return a;
return gcd(b,a%b);
}
bool is_int(const double& _val){
return (int)_val==_val;
}
int a,b,c,k,x,y,z;
double xyz1,xyz2,xyz3;
bool num[10],flag=false;
bool num_check(){
for(int i=1;i<10;i++)if(not num[i])return false;
return true;
}
bool num_use(const int& i){
return num[i];
}
bool check(){
xyz1=x*100+y*10+z,xyz2=xyz1/a*b,xyz3=xyz1/a*c;
int xx=(int)xyz2/100,yy=((int)xyz2-xx*100)/10,zz=(int)xyz2-xx*100-yy*10;
if(num_use(xx))return false;
else num[xx]=true;
if(num_use(yy))return false;
else num[yy]=true;
if(num_use(zz))return false;
else num[zz]=true;
//cout<<"xyz2 can!"<<endl;
xx=(int)xyz3/100,yy=((int)xyz3-xx*100)/10,zz=(int)xyz3-xx*100-yy*10;
if(num_use(xx))return false;
else num[xx]=true;
if(num_use(yy))return false;
else num[yy]=true;
if(num_use(zz))return false;
else num[zz]=true;
//cout<<"xyz3 can!"<<endl;
if(not is_int(xyz1) or not is_int(xyz2) or not is_int(xyz3))return false;
if(not num_check())return false;
if(xyz1>999)return false;
if(xyz2>999)return false;
if(xyz3>999)return false;
return true;
}
int main(){
cin>>a>>b>>c;
k=gcd(gcd(a,b),c);
a/=k,b/=k,c/=k;
for(x=1;x<=9;x++){
for(y=1;y<=9;y++){
if(y==x)continue;
for(z=1;z<=9;z++){
if(z==y or z==x)continue;
num[x]=num[y]=num[z]=true;
//cout<<x<<' '<<y<<' '<<z<<' '<<xyz1<<' '<<xyz2<<' '<<xyz3<<endl;
if(check()){
flag=true;
cout<<xyz1<<' '<<xyz2<<' '<<xyz3<<endl;
}
memset(num,false,sizeof(num));
}
}
}
if(not flag)cout<<"No!!!";
return 0;
}
以及神奇地,这题开了O2就正常了,但是最后一个点又会RE
by cygnus_beta @ 2021-05-30 11:57:05
但是本地gcc10.1开O2编译最后一个点又不会RE
by tobby3600 @ 2021-05-30 13:17:04
看了你这个我竟然会做了,感谢