Created
March 8, 2011 11:11
-
-
Save iporsut/860153 to your computer and use it in GitHub Desktop.
dare to hide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
#define MAX_ROW 64 | |
#define MAX_COLUMN 64 | |
#define ctoi(C) (C - '0') | |
typedef struct _room_pos { | |
int m; | |
int n; | |
} ROOM_POS; | |
char room[MAX_ROW][MAX_COLUMN]; | |
int room_width, room_long; | |
ROOM_POS killer_room; | |
void parse_input() { | |
int i,j; | |
char line_input[80]; | |
fgets(line_input,80,stdin); | |
sscanf((const char *)line_input,"%d %d",&room_width,&room_long); | |
fgets(line_input,80,stdin); | |
sscanf((const char *)line_input,"%d %d",&(killer_room.m),&(killer_room.n)); | |
for(i = 0; i < room_long; ++i) { | |
fgets(room[i],MAX_COLUMN,stdin); | |
room[i][strlen(room[i])-1] = '\0'; | |
} | |
} | |
int find_death_room() { | |
int count = 0; | |
int c; | |
int i; | |
/* N */ | |
for (c = killer_room.n-2; c >= 0; --c) { | |
i = ctoi(room[c][killer_room.m-1]) >> 1; | |
if (i) { | |
count++; | |
} else | |
break; | |
} | |
/* E */ | |
for (c = killer_room.m-1; c < room_width; ++c) { | |
i = ctoi(room[killer_room.n-1][c]) & 1; | |
if (i) { | |
count++; | |
} else | |
break; | |
} | |
/* S */ | |
for (c = killer_room.n-1; c < room_long; ++c) { | |
i = ctoi(room[c][killer_room.m-1]) >> 1; | |
if (i) { | |
count++; | |
} else | |
break; | |
} | |
/* W */ | |
for (c = killer_room.m-2; c >= 0; --c) { | |
i = ctoi(room[killer_room.n-1][c]) & 1; | |
if (i) { | |
count++; | |
} else | |
break; | |
} | |
return count; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
int i; | |
parse_input(); | |
printf("%d\n",(room_long*room_width)-find_death_room()-1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment