???

P1008 [NOIP1998 普及组] 三连击

> 将 $9$ 个数分成 $3$ 组 不能有重复的
by Yun_Mengxi_orz @ 2023-10-15 21:55:58


比如 `100 200 300` 就不符合要求,因为有 $0$ `123 246 369` 也不符合要求,因为有重复的数字
by Yun_Mengxi_orz @ 2023-10-15 21:56:50


```cpp #include<bits/stdc++.h> using namespace std; bool check(int a, int b, int c) { int used = 0, temp = 0; temp = a; while (temp) { if(temp % 10 == 0) return false; // 排除包含数字0的情况 used |= (1 << (temp % 10)); temp /= 10; } temp = b; while (temp) { if(temp % 10 == 0) return false; // 排除包含数字0的情况 used |= (1 << (temp % 10)); temp /= 10; } temp = c; while (temp) { if(temp % 10 == 0) return false; // 排除包含数字0的情况 used |= (1 << (temp % 10)); temp /= 10; } return used == (1 << 10) - 2; // 检查是否所有的数字(1到9)都被使用了 } int main(){ for (int i = 100; i <= 333; ++i) { if (check(i, i * 2, i * 3)) { printf("%d %d %d\n", i, i * 2, i * 3); } } return 0; } ```
by JYW2011 @ 2023-10-15 22:02:55


3Q
by MindustrySF @ 2023-10-17 09:38:53


```cpp #include<iostream> #include<algorithm> using namespace std; int main() { int A[] = { 1,2,3,4,5,6,7,8,9 }; int x1, x2, x3; do { x1 = A[0] * 100 + A[1] * 10 + A[2]; x2 = A[3] * 100 + A[4] * 10 + A[5]; x3 = A[6] * 100 + A[7] * 10 + A[8]; if (x1 * 2 == x2 && x2 * 3 == x3 * 2 && x1 * 3 == x3) { cout << x1 <<" "<< x2 <<" "<< x3 << endl; } } while (next_permutation(A,A+9)); return 0; }
by swuster27 @ 2024-02-24 14:04:18


|