题意:一个又n^2个小三角形组成的三角形又A,B两块三角形组成,问能否把它们分开
解题思路:平行于三条边移动。
解题代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // File Name: g.c 2 // Author: darkdream 3 // Created Time: 2013年09月09日 星期一 13时45分49秒 4 5 #include<stdio.h> 6 #include<string.h> 7 #include<stdlib.h> 8 #include<time.h> 9 #include<math.h> 10 #define LL long long 11 12 //freopen("/home/plac/problem/input.txt","r",stdin); 13 //freopen("/home/plac/problem/output.txt","w",stdout); 14 int a[200][200]; 15 int n ; 16 int ok1() 17 { 18 for(int i = 1;i <= n;i ++) 19 { 20 int k = 2*i-1; 21 for(int j = 1;j <= k; j ++) 22 if(a[i][j] == 0 && a[i][j-1] == 1) 23 { 24 k = 0 ; 25 return 0; 26 } 27 } 28 return 1; 29 } 30 int ok2() 31 { 32 for(int i = 1;i <= n;i ++) 33 { 34 int k = 2*i-1; 35 for(int j = 1; j <= k; j++) 36 if(a[i][j] == 0 && a[i][j+1] == 1) 37 { 38 return 0; 39 } 40 } 41 return 1; 42 } 43 int ok3() 44 { 45 for(int i = 1;i <= n;i ++) 46 { 47 int k = 2*i-1; 48 for(int j = 1; j <= k; j++) 49 if(a[i][j] == 0 ) 50 { 51 if(j % 2 == 1) 52 { 53 if(a[i][j-1] == 1) 54 return 0 ; 55 } 56 else 57 { 58 if(a[i-1][j-1] == 1) 59 return 0; 60 } 61 } 62 } 63 return 1; 64 } 65 int ok4() 66 { 67 for(int i = 1;i <= n;i ++) 68 { 69 int k = 2*i-1; 70 for(int j = 1; j <= k; j ++) 71 if(a[i][j] == 0 ) 72 { 73 if(j % 2 == 1) 74 { 75 if(a[i+1][j+1] == 1) 76 return 0 ; 77 } 78 else 79 { 80 if(a[i][j+1] == 1) 81 return 0; 82 } 83 } 84 } 85 return 1; 86 } 87 int ok5() 88 { 89 for(int i = 1;i <= n;i ++) 90 { 91 int k = 2*i-1; 92 for(int j = 1; j <= k ; j ++) 93 if(a[i][j] == 0 ) 94 { 95 if(j % 2 == 1) 96 { 97 if(a[i][j+1] == 1) 98 return 0 ; 99 } 100 else 101 { 102 if(a[i-1][j-1] == 1) 103 return 0; 104 } 105 } 106 } 107 return 1; 108 } 109 int ok6() 110 { 111 for(int i = 1;i <= n;i ++) 112 { 113 int k = 2*i-1; 114 for(int j = 1; j <= k; j ++) 115 if(a[i][j] == 0 ) 116 { 117 if(j % 2 == 1) 118 { 119 if(a[i+1][j+1] == 1) 120 return 0 ; 121 } 122 else 123 { 124 if(a[i][j-1] == 1) 125 return 0; 126 } 127 } 128 } 129 return 1; 130 } 131 int main(){ 132 int t = 0 ; 133 while(scanf("%d",&n)!= EOF && n) 134 { 135 int ok = 0 ; 136 memset(a,0,sizeof(a)); 137 t++; 138 for(int i = 1;i <= n;i ++) 139 { 140 int k = 2*i-1; 141 for(int j= 1 ;j <= k; j ++ ) 142 scanf("%1d",&a[i][j]); 143 } 144 if(ok1()||ok2()||ok3()||ok4()||ok5()||ok6()) 145 ok = 1; 146 printf("Puzzle %d\n",t); 147 if(ok) 148 printf("Parts can be separated\n"); 149 else printf("Parts cannot be separated\n"); 150 151 } 152 153 return 0 ; 154 }
没有梦想,何谈远方