1 条题解
-
0
做法 1:离线运算
生成“暴力枚举代码”的代码
#include<bits/stdc++.h> using namespace std; int main() { freopen("ans.cpp","w",stdout); cout<<"#include<bits/stdc++.h>\n"; cout<<"using namespace std;\n"; cout<<"int main(){\n"; cout<<" int cnt=0;\n"; for(char c='a';c<='j';c++) cout<<" for(int "<<c<<"=0;"<<c<<"<=9;"<<c<<"++)\n"; cout<<" {\n"; for(char i='a';i<='j';i++) for(char j=i+1;j<='j';j++) cout<<" if("<<i<<"=="<<j<<") continue;\n"; cout<<" int x=a*10000+b*1000+c*100+d*10+e;\n"; cout<<" int y=f*10000+g*1000+h*100+i*10+j;\n"; cout<<" if(x%y==0)\n"; cout<<" cnt++;\n"; cout<<" }\n"; cout<<" cout<<cnt;\n"; cout<<" return 0;\n"; cout<<"}\n"; return 0; }
暴力枚举
#include<bits/stdc++.h> using namespace std; int main(){ int cnt=0; for(int a=0;a<=9;a++) for(int b=0;b<=9;b++) for(int c=0;c<=9;c++) for(int d=0;d<=9;d++) for(int e=0;e<=9;e++) for(int f=0;f<=9;f++) for(int g=0;g<=9;g++) for(int h=0;h<=9;h++) for(int i=0;i<=9;i++) for(int j=0;j<=9;j++) { if(a==b) continue; if(a==c) continue; if(a==d) continue; if(a==e) continue; if(a==f) continue; if(a==g) continue; if(a==h) continue; if(a==i) continue; if(a==j) continue; if(b==c) continue; if(b==d) continue; if(b==e) continue; if(b==f) continue; if(b==g) continue; if(b==h) continue; if(b==i) continue; if(b==j) continue; if(c==d) continue; if(c==e) continue; if(c==f) continue; if(c==g) continue; if(c==h) continue; if(c==i) continue; if(c==j) continue; if(d==e) continue; if(d==f) continue; if(d==g) continue; if(d==h) continue; if(d==i) continue; if(d==j) continue; if(e==f) continue; if(e==g) continue; if(e==h) continue; if(e==i) continue; if(e==j) continue; if(f==g) continue; if(f==h) continue; if(f==i) continue; if(f==j) continue; if(g==h) continue; if(g==i) continue; if(g==j) continue; if(h==i) continue; if(h==j) continue; if(i==j) continue; int x=a*10000+b*1000+c*100+d*10+e; int y=f*10000+g*1000+h*100+i*10+j; if(x%y==0) cnt++; } cout<<cnt; return 0; }
本地运行暴力代码得到答案
#include<bits/stdc++.h> using namespace std; int main() { cout << "281\n"; return 0; }
做法 2
最多不会超过100,可以枚举 与 ,生成 ,检测是否正确。
#include<bits/stdc++.h> using namespace std; int main() { int cnt=0; for(int x=01234;x<=98765;x++) { for(int n=0;n<=100;n++) { int y = x * n; if(y<01234||y>98765) continue; int a=x/10000%10; int b=x/1000%10; int c=x/100%10; int d=x/10%10; int e=x%10; int f=y/10000%10; int g=y/1000%10; int h=y/100%10; int i=y/10%10; int j=y%10; if(a==b) continue; if(a==c) continue; if(a==d) continue; if(a==e) continue; if(a==f) continue; if(a==g) continue; if(a==h) continue; if(a==i) continue; if(a==j) continue; if(b==c) continue; if(b==d) continue; if(b==e) continue; if(b==f) continue; if(b==g) continue; if(b==h) continue; if(b==i) continue; if(b==j) continue; if(c==d) continue; if(c==e) continue; if(c==f) continue; if(c==g) continue; if(c==h) continue; if(c==i) continue; if(c==j) continue; if(d==e) continue; if(d==f) continue; if(d==g) continue; if(d==h) continue; if(d==i) continue; if(d==j) continue; if(e==f) continue; if(e==g) continue; if(e==h) continue; if(e==i) continue; if(e==j) continue; if(f==g) continue; if(f==h) continue; if(f==i) continue; if(f==j) continue; if(g==h) continue; if(g==i) continue; if(g==j) continue; if(h==i) continue; if(h==j) continue; if(i==j) continue; cnt++; } } cout<<cnt<<"\n"; return 0; }
- 1
信息
- ID
- 1294
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- (无)
- 递交数
- 51
- 已通过
- 33
- 上传者