_QrSn_ @ 2022-08-28 17:36:14
#include<bits/stdc++.h>
using namespace std;
//memset(d,0,sizeof d);
int a,b,c,d[11],ans,ans2,ans3,wa=0,sum=0,gcd3;
int gcd(int a,int b,int c)
{
int t;
t=a;
if(t>b) t=b;
if(t>c) t=c;
while(a%t!=0||b%t!=0||c%t!=0)t--;
return t;
}
int main() {
cin>>a>>b>>c;
gcd3=gcd(a,b,c);
a=a/gcd3,b=b/gcd3,c=c/gcd3;
//cout<<a<<" "<<b<<" "<<c<<" "<<gcd3<<endl;
if(a==0||b==0||c==0){cout<<"No!!!";return 0;}
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
for(int k=1;k<=9;k++)
{
d[i]++;d[j]++;d[k]++;
ans=i*100+j*10+k;
ans2=ans*b;
ans3=ans*c;
if(ans2/1000!=0){memset(d,0,sizeof d);continue;}
else if(ans3/1000!=0){memset(d,0,sizeof d);continue;}
d[ans2%10]++;d[ans2/10%10]++;d[ans2/100]++;
d[ans3%10]++;d[ans3/10%10]++;d[ans3/100]++;
if(d[0]!=0){memset(d,0,sizeof d);continue;}
for(int l=1;l<=9;l++)if(d[l]>=2){wa=1;break;}
if(wa==1){wa=0;memset(d,0,sizeof d);continue;}
else {cout<<ans<<" "<<ans2<<" "<<ans3<<endl;sum++;memset(d,0,sizeof d);}
}
}
}
if(sum==0)cout<<"No!!!";
return 0;
}
WA&RE https://www.luogu.com.cn/record/85369513
by juruolht @ 2022-08-28 17:44:19
用样例来说,我的写法是先把i看成一倍,j和k分别是2倍和三倍,把再看一下是否成立
by _QrSn_ @ 2022-08-28 17:45:51
@juruolht 我也是这样的,然后有一组数据,开头不是1,WA了,然后我把他化成最简整数比,1WA1RE
by bamboo12345 @ 2022-08-28 17:46:29
@QrSn RE的话你要把三个数中有零的判断放到gcd之前
by juruolht @ 2022-08-28 17:46:48
@QrSn 你是说hack数据吗?
by bamboo12345 @ 2022-08-28 17:48:12
@QrSn 有没有一种可能abc化简后a还是大于1呢?
by a2lyaXNhbWUgbWFyaXNh @ 2022-08-28 17:48:24
有必要写那么多MEMSET吗
#include<bits/stdc++.h>
using namespace std;
bool check(int x,int y,int z) {
int a[15]={0};
memset(a,0,sizeof(a));
while(x!=0) {
a[x%10]=1;
x/=10;
}
while(y!=0) {
a[y%10]=1;
y/=10;
}
while(z!=0) {
a[z%10]=1;
z/=10;
}
for(int i=1;i<10;i++){
if(a[i]==0){
return 0;
}
}
return 1;
}
int main() {
int x,y,z;
cin>>x>>y>>z;
bool f;
for(int i=1;;i++){
int a=x*i,b=y*i,c=z*i;
if(c>1000)break;
if(check(a,b,c)){
cout<<a<<" "<<b<<" "<<c<<endl;
f=1;
}
}
if(!f){
cout<<"No!!!";
}
return 0;
}
我爱暴力
by _QrSn_ @ 2022-08-28 17:48:25
@bamboo123 谢谢,RE解决了
by _QrSn_ @ 2022-08-28 17:49:05
@juruolht 应该是
by a2lyaXNhbWUgbWFyaXNh @ 2022-08-28 17:50:17
@QrSn
弱弱地问一句:为啥不直接枚举呢,优化后可以过啊
by LuminaryWay @ 2022-09-02 12:30:24
可以直接枚举