【染色】The Castle 城堡
来源:互联网 发布:广联达软件下载地址 编辑:程序博客网 时间:2024/06/10 15:45
The Castle 城堡
以一个几乎超乎想像的运气,农民约翰在他的生日收到了一张爱尔兰博彩的奖券.这一张奖券成为
了唯一中奖的奖券.农民约翰嬴得爱尔兰的乡下地方的一个传说中的城堡.
吹牛在他们威斯康辛州不算什么,农民约翰想告诉他的牛所有有关城堡的事.他想知道城堡有多少
房间,而且最大的房间有多大.事实上,他想去掉一面墙来制造一个更大的房间.
你的任务是帮助农民约翰去了解正确房间数目和大小.
城堡的平面图被分为 M(wide)*N(1 <=M,N<=50)个小正方形.
每个这样的小正方形有0到4面墙.
城堡在它的外部边缘总是有墙壁的,好遮挡风雨.
考虑这注解了一个城堡的平面图:
# =墙壁 -, | = 没有墙壁
-> =移除这面墙能使得到的新房间最大
例子的城堡的大小是 7 x 4.
一个 "房间"是平面图上有连接的"小正方形"的集合.
这个平面图包含五个房间.(它们的大小是 9,7,3,1, 和 8 排列没有特别的顺序).
移除被箭作记号的墙壁来合并两个房间来制造最大的可能房间(移除一面墙所能产生的).
城堡总是至少有二个房间并且总是有一面墙壁以可能被移除.
PROGRAM NAME: castle
INPUT FORMAT
地图以一个表格来储存,每个数字描述一个小正方形,N 行每行 M 个数来描述这个平面图.
输入顺序符合那个在上面例子的编号方式.
每个描述小正方形的数字说明小正方形的四面的墙的分布情况,它是下面 4 个数的和:
1: 在西面有墙
2: 在北面有墙
4: 在东面有墙
8: 在南面有墙
内部的墙壁是会被定义两次;小正方形(1,1)南面的墙也被指出是小正方形(2,1)北面的墙.
第 1 行: 二个被空格分开的整数: M 和 N
第 2 到: N+1 行: M x N 个整数,每行 M 个.
SAMPLE INPUT (file castle.in)
7 4
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13
OUTPUT FORMAT
输出包含一些行:
第 1 行: 城堡的房间数目.
第 2 行: 最大的房间的大小
第 3 行: 移除一面墙能得到的最大的房间的大小
第 4 行: 移除哪面墙
选择最佳的墙来移除,(选择最靠西的,如果仍然不能确定,再选择最靠南的.编者注:墙的位置应该
由它的中点来定义)
(【原文】Choose the optimal wall to remove from the set of optimal walls by choosing the
wall farther to the west (and then, if still tied, farthest to the south).)
墙壁由它在相邻的小正方形的西部或南方来命名
SAMPLE OUTPUT (file castle.out)
5
9
16
4 1 E
======================================
染色..
同cell。。
-------------------
题目条件的转化...(比较烦)
最后一个问...
同一染色的大小记录下来...
(注意:在计算的时候一定要是两个区域间拆墙..而不可以是同一区域内,这需要判断)
-------------------------------------
时隔1个月,在NOIP的前夕..我发现我在题目条件转化的情况下弄复杂很多了
实际可以这样做
但是顺序不可以错...orz各位神牛..
===========================================================
{ID:jie19952PROG:castleLANG:PASCAL}const dx:array[1..4]of longint=(0,-1,0,1); dy:array[1..4]of longint=(-1,0,1,0); dir:array[1..4]of char=('W','N','E','S');var m,n:longint; map:array[1..50,1..50]of longint; room_sum:array[1..2500]of longint; f_map:array[1..50,1..50,1..4]of boolean; f_bool,f_pd:array[0..51,0..51]of boolean; flag:longint;procedure init;begin assign(input,'castle.in'); assign(output,'castle.out'); reset(input); rewrite(output);end;procedure terminate;begin close(input); close(output); halt;end;procedure readdata;var i,j:longint;begin readln(m,n); fillchar(f_map,sizeof(f_map),true); fillchar(f_bool,sizeof(f_bool),false); for i:=1 to n do for j:=1 to m do begin read(map[i,j]); if map[i,j]=1 then begin f_map[i,j,1]:=false; end;{1} if map[i,j]=2 then begin f_map[i,j,2]:=false; end;{2} if map[i,j]=4 then begin f_map[i,j,3]:=false; end;{3} if map[i,j]=8 then begin f_map[i,j,4]:=false; end;{4} if map[i,j]=3 then begin f_map[i,j,1]:=false; f_map[i,j,2]:=false; end;{1,2} if map[i,j]=5 then begin f_map[i,j,1]:=false; f_map[i,j,3]:=false; end;{1,3} if map[i,j]=9 then begin f_map[i,j,1]:=false; f_map[i,j,4]:=false; end;{1,4} if map[i,j]=6 then begin f_map[i,j,2]:=false; f_map[i,j,3]:=false; end;{2,3} if map[i,j]=10 then begin f_map[i,j,2]:=false; f_map[i,j,4]:=false; end;{2,4} if map[i,j]=12 then begin f_map[i,j,3]:=false; f_map[i,j,4]:=false; end;{3,4} if map[i,j]=7 then begin f_map[i,j,1]:=false; f_map[i,j,2]:=false; f_map[i,j,3]:=false; end;{1,2,3} if map[i,j]=11 then begin f_map[i,j,1]:=false; f_map[i,j,2]:=false; f_map[i,j,4]:=false; end;{1,2,4} if map[i,j]=13 then begin f_map[i,j,1]:=false; f_map[i,j,3]:=false; f_map[i,j,4]:=false; end;{1,3,4} if map[i,j]=14 then begin f_map[i,j,2]:=false; f_map[i,j,3]:=false; f_map[i,j,4]:=false; end;{2,3,4} if map[i,j]=15 then begin f_map[i,j,1]:=false; f_map[i,j,2]:=false; f_map[i,j,3]:=false; f_map[i,j,4]:=false; end;{1,2,3,4} f_bool[i,j]:=true; end;end;function dfs(x,y:longint):longint;var i:longint; x_c,y_c:longint;begin dfs:=1; for i:=1 to 4 do begin x_c:=x+dx[i]; y_c:=y+dy[i]; if f_map[x,y,i] and f_pd[x_c,y_c] then begin if f_bool[x_c,y_c] then begin f_pd[x_c,y_c]:=false; map[x_c,y_c]:=flag; dfs:=dfs+dfs(x_c,y_c); end; end; end;end;procedure the_last;var i,j,k:longint; ans_size:longint; size_x,size_y:longint; ans_dir:char; x_c,y_c:longint;begin ans_size:=0; for i:=1 to n do for j:=1 to m do for k:=1 to 4 do begin x_c:=i+dx[k]; y_c:=j+dy[k]; if f_bool[x_c,y_c] and not f_map[i,j,k] then if (map[i,j]<>map[x_c,y_c]) then begin if (room_sum[map[i,j]]+room_sum[map[x_c,y_c]]>ans_size) then begin ans_dir:=dir[k]; ans_size:=room_sum[map[i,j]]+room_sum[map[x_c,y_c]]; size_x:=i; size_y:=j; end else if (room_sum[map[i,j]]+room_sum[map[x_c,y_c]]=ans_size) then begin if j<size_y then begin ans_dir:=dir[k]; ans_size:=room_sum[map[i,j]]+room_sum[map[x_c,y_c]]; size_x:=i; size_y:=j; end else if (j=size_y) and (i>size_x) then begin ans_dir:=dir[k]; ans_size:=room_sum[map[i,j]]+room_sum[map[x_c,y_c]]; size_x:=i; size_y:=j; end; end; end; end; writeln(ans_size); writeln(size_x,' ',size_y,' ',ans_dir);end;procedure main;var i,j:longint; t:longint; ans_sum,ans_size:longint;begin fillchar(f_pd,sizeof(f_pd),true); ans_sum:=0; ans_size:=0; flag:=0; for i:=1 to n do for j:=1 to m do if f_pd[i,j] then begin inc(flag); map[i,j]:=flag; f_pd[i,j]:=false; inc(ans_sum); t:=dfs(i,j); room_sum[flag]:=t; if ans_size<t then ans_size:=t; end; writeln(ans_sum); writeln(ans_size); the_last;end;begin init; readdata; main; terminate;end.
- 【染色】The Castle 城堡
- 城堡问题(The Castle)
- P1457 城堡 The Castle
- The Castle(城堡)
- 洛谷P1457 城堡(The Castle)
- USACO P1457 城堡 The Castle
- USACO2.1 城堡The Castle
- [USACO2.1]城堡 The Castle
- USACO 2.1.1The Castle城堡
- USACO:2.1.1 The Castle 城堡
- IOI 1994 The Castle 城堡问题
- 【搜索】洛谷 P1457 城堡 The Castle
- 【搜索】洛谷 P1457 城堡 The Castle
- poj-1164 The Castle 城堡 DFS计数
- USACO The Castle 种子染色法
- 【USACO题库】2.1.1 The Castle城堡 题解
- 【洛谷1457 [usaco 2.1]城堡 The Castle】【深搜】
- OpenJudge 2.5-1817&&166 城堡问题(The Castle)
- gluLookAt(eyex,eyey,eyez,centerx,centery,centerz,upx,upy,upz)使用说明
- 解决ubuntu下firefox升级到当前最新版本
- 2011/10/07 游戏AI
- typedef
- C#中关键字using的三种使用方法
- 【染色】The Castle 城堡
- linux文件的权限
- Qt之网络编程错误总结
- Be at peace, Steve Jobs
- Chapter 1: Working with strings
- These days thoughts
- sql 与Oracle对比
- java常用类解析五:IO系统File类及文件搜索工具类
- Kernel File and registry API