paiza スキルチェックB144

C

1#include <stdio.h>2 3int main(void){4 5 char str[1000];6 int h, w, n;7 int a[400][400];8 9 int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};10 int dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};11 12 fgets(str, sizeof(str), stdin);13 sscanf(str, "%d %d", &h, &w);14 fgets(str, sizeof(str), stdin);15 sscanf(str, "%d", &n);16 17 int i, j;18 for(i = 0; i < h; i++){19 for(j = 0; j < w; j++){20 //存在できる場合は1、できない場合は021 a[i][j] = 1;22 }23 }24 25 for(i = 0; i < n; i++){26 int x, y;27 fgets(str, sizeof(str), stdin);28 sscanf(str, "%d %d", &x, &y);29 30 a[y-1][x-1] = 0;31 32 for (j = 0; j < 8; j++) {33 int nx = x + dx[j];34 int ny = y + dy[j];35 if (nx >= 1 && nx <= h && ny >= 1 && ny <= w){36 a[ny - 1][nx - 1] = 0;37 }38 }39 }40 41 //何区画存在できるか42 int count = 0;43 for(i = 0; i < h; i++){44 for(j = 0; j < w; j++){45 if(a[i][j] == 1){46 count++;47 }48 }49 }50 51 printf("%d\n", count);52 53 return 0;54}

コメントを投稿

0 コメント