USACO 2.1 The Castle
2015-09-27 22:00
323 查看
#include <stdio.h> #define DEBUG 1 #define TESTCASES 8 int numOfRows, numOfColumns; int wall[50][50][4]; int numOfRooms; int roomNumArray[50][50]; int roomSize[2501]; int directionArray[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; void printRoomNumArray(){ int i, j; for (i = 0; i < numOfRows; i++){ for (j = 0; j < numOfColumns; j++) printf("%d ", roomNumArray[i][j]); printf("\n"); } printf("\n"); } void numberRoom(int row, int column, int roomNum){ //printRoomNumArray(); if (roomNumArray[row][column] != 0) return; roomNumArray[row][column] = roomNum; roomSize[roomNum]++; int directionIndex; for (directionIndex = 0; directionIndex < 4; directionIndex++){ int x = row + directionArray[directionIndex][0]; int y = column + directionArray[directionIndex][1]; if (x >= 0 && x < numOfRows && y >= 0 && y < numOfColumns && wall[row][column][directionIndex] != 1 && roomNumArray[x][y] == 0) numberRoom(x, y, roomNum); } } int main(){ #if DEBUG int testCase; for (testCase = 1; testCase <= TESTCASES; testCase++){ char inputFileName[20] = "inputx.txt"; inputFileName[5] = '1' + (testCase - 1); freopen(inputFileName, "r", stdin); printf("\n#%d\n", testCase); #endif scanf("%d%d", &numOfColumns, &numOfRows); int row, column; for (row = 0; row < numOfRows; row++) for (column = 0; column < numOfColumns; column++){ int num; scanf("%d", &num); int direction; for (direction = 0; direction < 4; direction++) wall[row][column][direction] = (num >> direction) & 1; } int roomNum = 1; for (row = 0; row < numOfRows; row++) for (column = 0; column < numOfColumns; column++){ roomSize[roomNum++] = 0; roomNumArray[row][column] = 0; } int maxRoomSize = 0; roomNum = 0; for (row = 0; row < numOfRows; row++) for (column = 0; column < numOfColumns; column++) if (roomNumArray[row][column] == 0){ numberRoom(row, column, ++roomNum); if (roomSize[roomNum] > maxRoomSize) maxRoomSize = roomSize[roomNum] ; } printf("%d\n%d\n", roomNum, maxRoomSize); int roomSizeCreated = 0; int maxRoomSizeCreated = 0; int rowToRemove = -1, columnToRemove = -1; char directionOfWallRemoved = '0'; for (column = 0; column < numOfColumns; column++) for (row = numOfRows - 1; row >= 0; row--){ int currentRoomNum = roomNumArray[row][column]; int eastColumn; if ((eastColumn = column + 1) < numOfColumns){ int eastRoomNum = roomNumArray[row][eastColumn]; if (currentRoomNum != eastRoomNum) if ( (roomSizeCreated = roomSize[eastRoomNum] + roomSize[currentRoomNum]) > maxRoomSizeCreated){ maxRoomSizeCreated = roomSizeCreated; rowToRemove = row; columnToRemove = column; directionOfWallRemoved = 'E'; } } int northRow; if ((northRow = row - 1) >= 0){ int northRoomNum = roomNumArray[northRow][column]; if (northRoomNum != currentRoomNum) if ( (roomSizeCreated = roomSize[northRoomNum] + roomSize[currentRoomNum]) > maxRoomSizeCreated){ maxRoomSizeCreated = roomSizeCreated; rowToRemove = row; columnToRemove = column; directionOfWallRemoved = 'N'; } } } printf("%d\n%d %d %c\n", maxRoomSizeCreated, rowToRemove + 1, columnToRemove + 1, directionOfWallRemoved); #if DEBUG } #endif return 0; }
相关文章推荐
- 推荐-新云网站管理系统 2.1 商业版(包含商城) 下载
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- 英语听写专家 2.1 Build 0086 注册码
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- Windows server2003下搭建openmeetings2.1视频会议系统
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- USACO 3.2.2:Stringsobits
- POJ1523 SPF dfs
- poj1731 Orders dfs
- Surrounded Regions
- Binary Tree Zigzag Level Order Traversal,Restore IP Addresses,Word Search,Simplify Path