JZOJ 3807 【NOIP2014模拟8.25】地砖铺设
2017-01-16 16:20
393 查看
地砖铺设
Description
给出一个长为N,宽为M的网格图,用一些由含有相同字母的正方形填满这个网格(一个正方形内含有的字母必须相同,不同的正方形含有的字母不一定相同),使得相邻的两个正方形含有的字母不同,输出字典序最小的满足条件的网格图。Data Constraint
N,M<=100Solution
贪心。从上到下,从左到右对网格图进行构造,然后每次判断 与前面的格子进行合并构成一个更大的正方形更优 还是 该格子作为一个新的正方形的左上顶点更优,选最优方案构造即可。
Code(Pascal)
var ch:array[0..1000,0..1000] of char; x,y,ok,bc:array[0..1000,0..1000] of longint; n,m,j,k,l,i:longint; bz:array['A'..'E'] of boolean; cc:char; begin readln(n,m); for i:=0 to n+1 do for l:=0 to m+1 do ch[i,l]:=' '; for l:=0 to m+1 do ch[0,l]:='E'; for l:=0 to n+1 do ch[l,0]:='E'; for i:=1 to n do begin for l:=1 to m do begin if ch[i,l]<>' ' then continue; ok[i,l]:=1; fillchar(bz,sizeof(bz),true); bz[ch[i,l-1]]:=false; bz[ch[i-1,l]]:=false; if ch[i,l+1]<>' ' then bz[ch[i,l+1]]:=false; for cc:='A' to 'E' do if bz[cc] then break; bc[i,l]:=1; if ch[i,l-1]>cc then ch[i,l]:=cc else if (ok[i,l-1]=1) and (ch[i-1,l]<>ch[i,l-1]) and (i+bc[i,l-1]<=n) then begin for j:=1 to bc[i,l-1] do ch[i+j-1,l]:=ch[i,l-1]; bc[i,l]:=bc[i,l]+bc[i,l-1]; for j:=l downto l-bc[i,l-1] do ch[i+bc[i,l-1],j]:=ch[i,l-1]; end else ch[i,l]:=cc; end; end; for i:=1 to n do begin for l:=1 to m do write(ch[i,l]); writeln; end; end.
相关文章推荐
- JZOJ 3807. 【NOIP2014模拟8.25】地砖铺设
- JZOJ 3807. 【NOIP2014模拟8.25】地砖铺设
- 【NOIP2014模拟8.25】地砖铺设
- JZOJ 3808 【NOIP2014模拟8.25】道路值守
- JZOJ 3808. 【NOIP2014模拟8.25】道路值守
- JZOJ 3809. 【NOIP2014模拟8.25】设备塔
- JZOJ 3809. 【NOIP2014模拟8.25】设备塔
- JZOJ 3809 【NOIP2014模拟8.25】设备塔
- 【JZOJ3824】【NOIP2014模拟9.9】渴
- JZOJ NOIP2014模拟 8.12
- jzoj3927【NOIP2014模拟11.6】可见点数(欧拉函数)
- jzoj. 3838. 【NOIP2014模拟9.14】Super Big Stupid Cross
- JZOJ 3806. 【NOIP2014模拟8.24】小X 的道路修建
- JZOJ 3775. 【NOIP2014模拟8.15】因子的排列
- 【JZOJ】 【NOIP2014】【模拟试题】保镖排队
- JZOJ 3927. 【NOIP2014模拟11.6】可见点数
- jzoj. 3889. 【NOIP2014模拟10.25B组】序列问题
- JZOJ-senior-3910. 【NOIP2014模拟11.1A组】Idiot 的间谍网络
- 【JZOJ3824】【NOIP2014模拟9.9】渴
- JZOJ3815. 【NOIP2014模拟9.7】克卜勒