fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //variable
  5. int arr[1001][1001];
  6. int a,b;
  7. void scan_P(int i,int j){
  8. arr[i][j] = 1;
  9. }
  10.  
  11. void scan_K(int i,int j){
  12. for(int i1=i-1;i1 <=i+1;i1++){
  13. if(i1 <0 || i1 >=a ||i1 ==i){
  14.  
  15. }else{
  16. if((j+2) < b ){
  17. arr[i1][j+2] = 1;
  18. }
  19. if((j-2) >=0){
  20. arr[i1][j-2] = 1;
  21. }
  22. }
  23. }
  24. for(int j1=j-1;j1 <=j+1;j1++){
  25. if(j1 <0 || j1 >=b ||j1 == j){
  26.  
  27. }else{
  28. if((i+2) < a){
  29. arr[i+2][j1] = 1;
  30. }
  31. if((i-2) >= 0){
  32. arr[i-2][j1] = 1;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. void scan_Q(int i,int j){
  39. arr[i][j] = 1;
  40. for(int i1=i+1;i1<a;i1++){
  41. if(arr[i1][j] == 1){
  42. break;
  43. }else{
  44. arr[i1][j] = 1;
  45. }
  46. }
  47. for(int i1=i-1;i1>=0;i1--){
  48. if(arr[i1][j] == 1){
  49. break;
  50. }else{
  51. arr[i1][j] = 1;
  52. }
  53. }
  54. for(int j1=j+1;j1<b;j1++){
  55. if(arr[i][j1] == 1){
  56. break;
  57. }else{
  58. arr[i][j1] = 1;
  59. }
  60. }
  61. for(int j1=j-1;j1>=0;j1--){
  62. if(arr[i][j1] == 1){
  63. break;
  64. }else{
  65. arr[i][j1] = 1;
  66. }
  67. }
  68. for(int i1 = i-1;i1 >= 0;i1--){
  69. int j1 = j- (i-i1);
  70. if(j1 <0){
  71. break;
  72. }
  73. if(arr[i1][j1] == 1){
  74. break;
  75. }else{
  76. arr[i1][j1] = 1;
  77.  
  78. }
  79. }
  80. for(int i1 = i-1;i1 >= 0;i1--){
  81. int j1 = j+ (i-i1);
  82. if(j1 >=b){
  83. break;
  84. }
  85. if(arr[i1][j1] == 1){
  86. break;
  87. }else{
  88. arr[i1][j1] = 1;
  89. }
  90. }
  91. for(int i1 = i+1; i1 <a;i1++){
  92. int j1 = j-(i1-i);
  93. if(j1 <0){
  94. break;
  95. }
  96. if(arr[i1][j1] == 1 ){
  97. break;
  98. }else{
  99. arr[i1][j1] = 1;
  100. }
  101. }
  102. for(int i1 = i+1; i1 < a;i1++){
  103. int j1 = j+(i1-i);
  104. if(j1 >= b){
  105. break;
  106. }
  107. if(arr[i1][j1] == 1 || j1 >=b){
  108. break;
  109. }else{
  110. arr[i1][j1] = 1;
  111. }
  112. }
  113. }
  114. int ret_val(){
  115. int res = 0;
  116. for(int i=0;i<a;i++){
  117. for(int j=0;j<b;j++){
  118. if(arr[i][j] == 0){
  119. res++;
  120. }
  121. }
  122. }
  123. return res;
  124. }
  125. int main(){
  126. //freopen("input.txt","r",stdin);
  127. int test = 1;
  128. scanf("%d %d",&a,&b);
  129. while(a >0 && b > 0){
  130. memset(arr,0,sizeof(arr));
  131. int num_q,num_k,num_p;
  132. int arr1[202],arr2[202],arr3[202];
  133. scanf("%d",&num_q);
  134. for(int i=0;i<2*num_q;i++){
  135. scanf("%d",&arr1[i]);
  136. }
  137. scanf("%d",&num_k);
  138. for(int i=0;i<2*num_k;i++){
  139. scanf("%d",&arr2[i]);
  140. }
  141. scanf("%d",&num_p);
  142. for(int i=0;i<2*num_p;i++){
  143. scanf("%d",&arr3[i]);
  144. }
  145. //Scan P
  146. for(int i=0;i<num_p;i++){
  147. scan_P(arr3[2*i]-1,arr3[2*i+1]-1);
  148. }
  149.  
  150. for(int i=0;i<num_k;i++){
  151. arr[arr2[2*i]-1][arr2[2*i+1]-1] = 1;
  152. }
  153. //Scan_Q
  154. for(int i=0;i<num_q;i++){
  155. scan_Q(arr1[2*i]-1,arr1[2*i+1]-1);
  156. }
  157. //ScaN K
  158. for(int i=0;i<num_k;i++){
  159. scan_K(arr2[2*i]-1,arr2[2*i+1]-1); // 1 4 0 3
  160. }
  161. // for(int i=0;i<a;i++){
  162. // for(int j=0;j<b;j++){
  163. // printf("%d ",arr[i][j]);
  164. // }
  165. // printf("\n");
  166. // }
  167. printf("Board %d has %d safe squares.\n",test,ret_val());
  168. test++;
  169. scanf("%d %d",&a,&b);
  170.  
  171. }
  172. return 0;
  173. }
Success #stdin #stdout 0.01s 5440KB
stdin
4 4
2 1 4 2 4
1 1 2
1 2 3
2 3
1 1 2
1 1 1
0
1000 1000
1 3 3
0
0
0 0
stdout
Board 1 has 6 safe squares.
Board 2 has 0 safe squares.
Board 3 has 996998 safe squares.