USACO 2.1 The Castle
来源:互联网 发布:多益网络绑定战盟 编辑:程序博客网 时间:2024/04/30 06:20
BFS用洪水填充染色。 记录每个颜色的房间数量
然后按照从下往上,从左往右的顺序穷举一边,拆掉墙,如果墙两边的房间颜色相同,跳过。 颜色不同,把颜色所代表的房间数量相加,和答案对比,更新答案即可。
Compiling...Compile: OKExecuting... Test 1: TEST OK [0.008 secs, 3572 KB] Test 2: TEST OK [0.008 secs, 3572 KB] Test 3: TEST OK [0.005 secs, 3572 KB] Test 4: TEST OK [0.008 secs, 3572 KB] Test 5: TEST OK [0.008 secs, 3572 KB] Test 6: TEST OK [0.008 secs, 3704 KB] Test 7: TEST OK [0.008 secs, 3572 KB] Test 8: TEST OK [0.022 secs, 3704 KB]All tests OK.
/*TASK:castleLANG:C++*/#include <iostream>#include <cstdio>#include <vector>#include <queue>using namespace std; int wall[55][55]={0};vector<int>path[2510];int m, n, t=0;int my_map[55][55]={0}, colo[2510] = {0}, colo_kinds=0;int room_size[2510];const int dx[]={0,0,-1,0,1};const int dy[]={0,-1,0,1,0};const int D[] = {0,1,2,4,8}; void init(){for (int i = 1; i <= m; ++ i)for (int j = n; j != 0; -- j)my_map[j][i] = ++t;for (int i = 1; i <= n; ++ i)for (int j = 1; j <= m; ++ j){cin >> wall[i][j];for (int k = 1; k <= 4; ++ k)if (!(wall[i][j] & D[k]))path[my_map[i][j]].push_back(my_map[i + dx[k]][j + dy[k]]);}} queue<int>q;void doit(){int max_room = 0;for (int i = 1; i <= m; ++ i)for (int j = n; j != 0; -- j){int tmp = my_map[j][i];if (colo[tmp])continue;q.push(tmp);colo[tmp] = ++ colo_kinds;room_size[colo_kinds] = 1;while (!q.empty()){int now = q.front();q.pop();for (int i = 0; i != path[now].size(); ++ i){int will = path[now][i];if (!will || colo[will])continue;++ room_size[colo_kinds];colo[will] = colo_kinds;q.push(will);}max_room = max(max_room, room_size[colo_kinds]);}}cout<<colo_kinds<<endl;cout<<max_room<<endl;max_room = 0;int dir(0);int tmpx, tmpy; for (int i = 1; i <= m; ++ i)for (int j = n; j != 0; -- j){for (int k = 1; k <= 4; ++ k){int now = colo[my_map[j][i]];int will = colo[my_map[j + dx[k]][i + dy[k]]];if (now == will)continue;int tmp = room_size[now] + room_size[will];if (tmp > max_room){tmpx = j;tmpy = i;max_room = tmp;dir = k;}}}cout<<max_room<<endl;cout<<tmpx<<" "<<tmpy<<" ";if (dir == 2)cout<<'N'<<endl;else cout<<'E'<<endl;} int main(){freopen("castle.in", "r", stdin);freopen("castle.out", "w", stdout);std::ios::sync_with_stdio(false);cin >>m >> n;init();doit();return 0;}
0 0
- USACO 2.1 The Castle (castle)
- USACO 2.1 The Castle
- USACO 2.1 The Castle
- USACO--2.1The Castle
- USACO 2.1 The Castle
- USACO[2.1]The Castle
- USACO 2.1-The Castle
- USACO 2.1 The Castle
- Usaco Section 2.1 The Castle
- USACO 2.1.1The Castle
- [USACO 2.1.1] The Castle
- USACO 2.1.1The Castle
- USACO Section 2.1 The Castle
- USACO Section 2.1 The Castle
- USACO 2.1.1 The Castle
- USACO-2.1.1- The Castle
- USACO section 2.1 The Castle(dfs)
- USACO 2.1.1The Castle城堡
- 内核设备模型分析
- 发送带附件的邮件 java
- 【AC自动机】 HDOJ 5164 Matching on Arrayy
- 不止是产品经理(一)----作为刚入行产品经理,如何开展工作?
- 黑马程序员--线程
- USACO 2.1 The Castle
- 设计模式一:单例模式
- Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)
- 解决 ubuntu14.04 chromium flash 问题
- Android内存泄露分析(MemoryAnalyzer工具)
- 12.3.3.1 序列表达式中的平面映射
- 我的2014
- 使用XFire+Spring构建Web Service(一)——helloWorld篇
- poj 1573 模拟