1 条题解
-
0
C :
#include <stdio.h> void show(int *x); int judege(int *x); void curision(int *x, int n); int main() { int x[10]; curision(x,0); return 0; } void show(int *x) { for(int i=0; i<10; i++) if(x[i]>0) printf("%c ", i+'A'); putchar(10); } int judge(int *x) { int t1= x[0]==0 || x[1]==1; int t2= x[2]==1 || x[3]==0; int t3= x[0] + x[2] <= 1; int t4= x[1] + x[3] == 1; int t5= x[3] + x[4] + x[5] + x[6] + x[7] >=2; int t6= (x[2]+x[6]==2) || (x[2]+x[6]==0); int t7= x[2]+x[4]+x[6]+x[8] <= 2; int t8= x[4]==0 || (x[5] + x[6]==2); int t9= x[5]==0 || (x[6] + x[7]==0); int t10= (x[8]+x[9]>0) || x[7]==1; return t1 && t2 && t3 && t3 && t4 && t5 && t6 && t7 && t8 && t9 && t10; } void curision(int *x, int n) { if(n>=10) { if(judge(x)) show(x); return; } x[n]=0; curision(x,n+1); x[n]=1; curision(x,n+1); }
C++ :
#include <iostream> using namespace std; #define N 10 int a[N]; void f(int idx) { int i,j; if(idx==N) { bool b[N]; b[0] = a[1] == 1 || a[0] == 0; b[1] = a[3] == 0 || a[2] == 1; b[2] = a[0] + a[2] <= 1;//a[0] + a[2] != 2 b[3] = a[1] != a[3];//b[3] = a[1] + a[3] == 1; b[4] = a[3] + a[4] + a[5] + a[6] + a[7] >= 2; b[5] = a[2]==a[6];//b[5] = a[2] + a[6] != 1; b[6] = a[2] + a[4] + a[6] + a[8] <= 2; b[7] = a[5] + a[6] == 2 || a[4] == 0; b[8] = a[6] + a[7] == 0 || a[5] == 0; b[9] = a[7] == 1 || a[8] + a[9] != 0; for (i = 0; i < N; i++) { if (!b[i]) break; } if (i == 10) { for (j = 0; j < N; j++) { if (a[j]) cout<<char(j+'A')<<' '; } cout<<endl; } return; } a[idx]=0; f(idx+1); a[idx]=1; f(idx+1); } int main() { f(0); return 0; }
Java :
public class Main { public static void main(String[] args) { for (int A = 0; A < 2; A++) { for (int B = 0; B < 2; B++) { if (A == 1 && B != 1) continue; for (int C = 0; C < 2; C++) { if (A + C == 2) continue; for (int D = 0; D < 2; D++) { if (C == 0 && D != 0) continue; if (B + D != 1) continue; for (int E = 0; E < 2; E++) { for (int F = 0; F < 2; F++) { for (int G = 0; G < 2; G++) { if(C+G==1) continue; if(E ==1 ) if(F + G != 2) continue; for (int H = 0; H < 2; H++) { if (D + E + F + G + H < 2) continue; if(F == 1) if(G + H != 0) continue; for (int I = 0; I < 2; I++) { if(C + E + G + I > 2) continue; for (int J = 0; J < 2; J++) { if(I==0 && J==0 && H!=1) continue; int[] result = {A,B,C,D,E,F,G,H,I,J}; for (int k = 0; k < result.length; k++) { if(result[k]==1) System.out.print((char)(65 + k)+" "); } System.out.println(); } } } } } } } } } } } }
- 1
信息
- ID
- 838
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者