81 条题解
-
16
1239285344 LV 7 @ 2018-09-03 18:48:31
#include<iostream>
using namespace std;int main()
{
cout<<"192 "<<"384 "<<"576"<<endl;
cout<<"219 "<<"438 "<<"657"<<endl;
cout<<"273 "<<"546 "<<"819"<<endl;
cout<<"327 "<<"654 "<<"981"<<endl;
return 0;
} -
72018-09-02 18:30:27@
致小白
#include <iostream> using namespace std; int main() { int x,a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3; for(x=123;x<=333;x++) { a=x;b=x*2;c=x*3; a1=a%10; a2=a/10%10; a3=a/100; b1=b%10; b2=b/10%10; b3=b/100; c1=c%10; c2=c/10%10; c3=c/100; if(a1*a2*a3*b1*b2*b3*c1*c2*c3==362880) cout<<a<<' '<<b<<' '<<c<<endl; } return 0; }
-
62017-03-12 08:56:53@
题解:
如果顺着题目枚举的话很容易爆;
所以要反过来想数据之间的关系;
三个数一定是1:2:3的;
那么我们只要循环一个基数作为3者公因数就OK,只需循环100~334;
时间效率prrety高。
主程序:
pan判断函数就不贴了for i:= 100 to 334 do
begin
a1:=1*i; a2:=2*i; a3:=3*i;
if pan then writeln(a1,' ',a2,' ',a3);
end; -
42017-07-22 11:27:28@
python 4行代码
python
for n in range(123, 330):
s = str(n) + ' ' + str(2*n) + ' ' + str(3*n)
if '1' in s and '2' in s and '3' in s and '4' in s and '5' in s and '6' in s and '7' in s and '8' in s and '9' in s:
print s
-
32018-06-28 18:40:03@
这里提供一个码量较大的代码(可能是我没有圧行)
思路:
判断三个数字中是不是只含1~9
只要排下序再一个个比对就可以啦QAQ
AC code:
#include<iostream> using namespace std; int main(){ int i,j,k,h,s; int a[10]; for(i=123;i*3<=987;i++){ for(h=1;h<10;h++)a[h]=0; a[i/100]=1; a[i/10%10]=1; a[i%10]=1; j=i*2; a[j/100]=1; a[j/10%10]=1; a[j%10]=1; k=i*3; a[k/100]=1; a[k/10%10]=1; a[k%10]=1; for(s=0,h=1;h<10;h++)s=s+a[h]; if(s==9)cout<<i<<" "<<j<<" "<<k<<endl; } return 0; }
-
22018-05-25 17:42:44@
看了好多方法都比较麻烦,尤其是判断语句过于复杂,这里介绍一种比较简单的java实现
import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] args) { Set set = new HashSet<>(); //遍历第一个数(只需要遍历123-334即可) for (int i = 123; i <= 334; i++) { int i2=2*i; int i3=3*i; String string = ""+i+i2+i3;//将3个数转换为一个字符串 char[] c=string.toCharArray();//将字符串转为字符数组 for (int j = 0; j < c.length; j++) { //将不等于0的字符存放入set集合中 if (c[j]!='0') { set.add(c[j]); }else { break; } } //利用set集合不重复的原理,如果set集合长度等于9说明9个数字皆不重复,打印结果 if (set.size()==9) { System.out.println(i+" "+i2+" "+i3); } //清除set集合 set.clear(); } } }
-
12022-01-01 10:39:55@
//借助set容器
//1772 vijos 巧妙填数 void test113() { set<int>s1; for (int i = 100; i <= 333; i++) { int p = i; int t = 2 * i; int m = 3 * i; while (p != 0) { int z = p % 10; if(z!=0) s1.insert(z); p /= 10; } while (t != 0) { int z = t % 10; if(z!=0) s1.insert(z); t /= 10; } while (m != 0) { int z = m % 10; if(z!=0) s1.insert(z); m/= 10; } if (s1.size() == 9) { cout << i << " " << 2 * i <<" "<< 3 * i << endl; s1.clear(); } else { s1.clear(); } } } int main() { test113(); }
-
12021-11-02 16:19:09@
#include <iostream> using namespace std; int main() { cout<< "192 "<< "384 "<< "576"<< endl; cout<< "219 "<< "438 "<< "657"<< endl; cout<< "273 "<< "546 "<< "819"<< endl; cout<< "327 "<< "654 "<< "981"<< endl; //system("pause"); return 0; } //xD
-
12021-07-13 10:57:36@
快
cpp
#include<stdio.h>
int main()
{
printf("192 384 576\n219 438 657\n273 546 819\n327 654 981");
return 0;
}
-
12020-02-04 19:15:50@
排列组合的思想
1.1-9全排列
2.判断是否满足条件
递归实现全排列
1.顺序抽取一个数
2.每当抽取了一个数据之后,对剩下的数据全排列
3.最后全部抽取完,剩下空字符串#include<iostream> #include<string> #include<cmath> using namespace std; int a, b, c; int num[9]; bool Judge(int num[]) {//条件判断 a = 0; b = 0; c = 0; int i = 0; for (; i < 3; i++)a += num[i] * (int)pow(10, 2 - i); for (; i < 6; i++)b += num[i] * (int)pow(10, 5 - i); for (; i < 9; i++)c += num[i] * (int)pow(10, 8 - i); if (b == 2 * a && c == 3 * a)return true; else return false; } void Count(string x, int n) {//全排列函数 if (n == 0 && Judge(num))cout << a << " " << b << " " << c << endl; else for (int i = 0; i < n; i++) { num[9 - n] = x[i] - 48; string y = x; y.replace(i, 1, ""); Count(y, n - 1); } } int main() { Count("123456789", 9); return 0; }
-
12019-07-26 18:21:03@
暴力枚举法:
#include<iostream> using namespace std; int a[350],b[350],c[350]; void f(int x,int y,int z); int main() { int n=100,t=1; while(n*3<1000) { a[t]=n*1; b[t]=n*2; c[t]=n*3; t++; n++; } for(int i=1;i<=n;i++) f(a[i],b[i],c[i]); return 0; } void f(int x,int y,int z) { int j[10]={0,0,0,0,0,0,0,0,0,0}; int x1=x,y1=y,z1=z; for(int i=1;i<=3;i++) { j[x1%10]++;j[y1%10]++;j[z1%10]++; x1=(x1-x1%10)/10; y1=(y1-y1%10)/10; z1=(z1-z1%10)/10; } for(int i=1;i<=9;i++) if(j[i]>1||j[i]==0) return; cout<<x<<" "<<y<<" "<<z<<endl; }
-
12019-02-04 09:42:52@
利用集合做的
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstdlib> #include <set> using namespace std; int a,b,c,i,j,k,i1,i2,j1,j2,k1,k2; void insertAll(set<int> &s){ s.insert(i),s.insert(j),s.insert(k); s.insert(i1),s.insert(j1),s.insert(k1); s.insert(i2),s.insert(j2),s.insert(k2); } int main(){ for(i=1; i<4; i++){ for(j=1;j<=9;j++){ for(k=1;k<=9;k++){ if(k!=i && k!=j && i!=j){ set<int> s; a = i*100+j*10+k; b = a*2; c = a*3; if(c>=1000) break; i1 = b/100; j1 = b%100/10; k1 = b%10; i2 = c/100; j2 = c%100/10; k2 = c%10; insertAll(s); if(s.size()==9&&!s.count(0)){ printf("%d %d %d\n",a,b,c); } } } } } }
-
12018-09-02 18:29:48@
致小白
-
12018-07-10 17:36:55@
直接用C++的全排列函数next_permutation,然后超过333不可能直接跳出
#include <iostream> #include <algorithm> using namespace std; int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; do{ // for(int i = 0; i < 9; ++i) printf("%d ", arr[i]); // printf("\n"); int num[3]; for(int i = 0;i < 3; ++i) { num[i] = arr[3 * i] * 100 + arr[3 * i + 1] * 10 + arr[3 * i + 2]; } if(num[0] > 333) break; if(num[0] * 2 == num[1] && num[0] * 3 == num[2]) printf("%d %d %d\n", num[0], num[1], num[2]); }while(next_permutation(arr, arr + 9)); return 0; }
-
12018-04-02 13:15:56@
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int r;
for (int i=123;i<=987;i++)
{
if ((i%10!=i/100)&&(i%10!=(i-i/100*100)/10)&&(i/100!=(i-i/100*100)/10))
{
for (int j=2*i;j<=987;j+=i)
{
r=i*3;
if (r<=987&&r==j*1.5&&(j%10!=j/100)&&(j%10!=(j-j/100*100)/10)&&(j/100!=(j-j/100*100)/10)&&(r%10!=r/100)&&(r%10!=(r-r/100*100)/10)&&(r/100!=(r-r/100*100)/10)&&j/100!=i/100&&j/100!=i%10&&j/100!=(i-i/100*100)/10&&r/100!=i/100&&r/100!=i%10&&r/100!=(i-i/100*100)/10&&j/100!=r/100&&j/100!=r%10&&j/100!=(r-r/100*100)/10&&j%10!=i/100&&j%10!=i%10&&j%10!=(i-i/100*100)/10&&r%10!=i/100&&r%10!=i%10&&r%10!=(i-i/100*100)/10&&j%10!=r/100&&j%10!=r%10&&j%10!=(r-r/100*100)/10&&(j-j/100*100)/10!=r/100&&(j-j/100*100)/10!=r%10&&(j-j/100*100)/10!=(r-r/100*100)/10&&(j-j/100*100)/10!=i/100&&(j-j/100*100)/10!=i%10&&(j-j/100*100)/10!=(i-i/100*100)/10&&j%10!=0&&j/100!=0&&(j-j/100*100)/10!=0&&r%10!=0&&r/100!=0&&(r-r/100*100)/10!=0&&i%10!=0&&i/100!=0&&(i-i/100*100)/10!=0)
{
cout<<i<<" "<<j<<" "<<r<<endl;
}
}
}
}
return 0;
}
if语句中,全为判断 -
12018-02-26 21:46:09@
#include<bits/stdc++.h> int main(){ char s[10]; bool flag[10]={0},flag2=0; for(int i=123;i<=329;++i){ sprintf(s+1,"%d%d%d",i,i*2,i*3); flag[0]=1;//确保0不出现 for(int j=1;j<=9;++j) if(1^flag[s[j]-'0']) flag[s[j]-'0']=1;else flag2=1;//用异或保证每个数字只出现一次 if(!(flag2)) printf("%d %d %d\n",i,i*2,i*3); memset(flag,0,sizeof(flag));flag2=0; } }
-
12018-02-09 22:36:34@
java来一波,感觉想复杂了。
public class FillNumber { public static void main(String[] args) { for (int i = 100; i <= 334; i ++) { int num1 = i; int num2 = i * 2; int num3 = i * 3; if(isConform(num1,num2,num3)) { System.out.println(num1 + " " + num2 + " " + num3); } } } public static boolean isConform(int a, int b, int c) { int[] arr = new int[9]; boolean[] check = new boolean[9]; for (int i = 0; i < 9; i ++) { arr[i] = i + 1; check[i] = true; } int a1 = a % 10; int a2 = (a / 10) % 10; int a3 = a / 100; int b1 = b % 10; int b2 = (b / 10) % 10; int b3 = b / 100; int c1 = c % 10; int c2 = (c / 10) % 10; int c3 = c / 100; for (int i = 0; i < arr.length; i ++) { if (check[i]) { if (arr[i] == a1 || arr[i] == a2 || arr[i] == a3) { check[i] = false; continue; } if (arr[i] == b1 || arr[i] == b2 || arr[i] == b3) { check[i] = false; continue; } if (arr[i] == c1 || arr[i] == c2 || arr[i] == c3) { check[i] = false; continue; } } } boolean flag = true; for (int i = 0; i < check.length; i ++) { if (check[i]) { flag = false; } } if(flag) { return true; } return false; } }
-
12018-01-02 15:35:29@
#include <stdio.h>
int main() {
int min,i,j,flag;
char all[10];
for(min = 102; min <=329; min++) {
sprintf(all,"%d%d%d",min,min*2,min*3);
flag = 0;
for(j = 1; j <= 9; j++) {
for(i = 0; i <=8; i++) {
if(all[i] == j+'0') {
flag++;
break;
}
}
}
//如果1到9都在字符串出现
if(flag == 9) {
printf("%d %d %d\n",min,2*min,3*min);
}
}
return 0;
} -
12017-08-22 19:42:49@
var f:array[1..9]of boolean;i:integer; procedure p(a:integer); begin f[a mod 10]:=false; f[a div 10 mod 10]:=false; f[a div 100]:=false; end; function pd(b:integer):boolean; var g,s,ba:integer; begin g:=b mod 10;s:=b div 10 mod 10;ba:=b div 100; if (g=s)or(g=ba)or(ba=s)or(f[g]=false)or(f[s]=false)or(f[ba]=false)then exit(true) else begin p(b); exit(false); end; end; begin for i:=102 to 329 do begin fillchar(f,sizeof(f),true); if pd(i) then continue; if pd(i*2) then continue; if pd(i*3) then continue; writeln(i,' ',i*2,' ',i*3); end; end.
-
02022-08-16 10:46:56@
next_permutation
#include<bits/stdc++.h> using namespace std; int main() { int a[10]={1,2,3,4,5,6,7,8,9}; do { int x=a[0]*100+a[1]*10+a[2]; int y=a[3]*100+a[4]*10+a[5]; int z=a[6]*100+a[7]*10+a[8]; if(y%x==0&&y/x==2&&z%x==0&&z/x==3) { printf("%d %d %d\n",x,y,z); } } while(next_permutation(a,a+9)); return 0; }