Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void fill(int **a, int w, int h, int c, int y, int x){
- if(y > 0 && a[y-1][x]==0){
- a[y-1][x]=c;
- fill(a,w,h,c,y-1,x);
- }
- if(y < h - 1 && a[y+1][x]==0){
- a[y+1][x]=c;
- fill(a,w,h,c,y+1,x);
- }
- if(x>0 && a[y][x-1]==0){
- a[y][x-1]=c;
- fill(a,w,h,c,y,x-1);
- }
- if(x < w - 1 && a[y][x+1]==0){
- a[y][x+1]=c;
- fill(a,w,h,c,y,x+1);
- }
- }
- int main() {
- int w,h,n;
- scanf("%d %d \n %d",&w,&h,&n);
- int **field = (int**)calloc(h,sizeof(int*));
- for(int i = 0; i < h; i++){
- field[i]=(int*)calloc(w,sizeof(int));
- }
- for(int i = 0; i < n; i++){
- char c;
- int x,y,len;
- scanf(" %c %d %d %d",&c,&x,&y,&len);
- if(c=='n'){
- for(int j = 0; j < len; j++){
- field[y++][x] = -1;
- }
- }else{
- for(int j = 0; j < len; j++){
- field[y][x++] = -1;
- }
- }
- }
- int c = 1;
- for(int i = 0; i < h; i++){
- for(int j = 0; j < w; j++){
- if(field[i][j]==0){
- fill(field,w,h,c,i,j);
- c++;
- }
- }
- }
- printf("%d\n",c-1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement