BZOJ2283: [Sdoi2011]火星移民
Description
在2xyz年,人类已经移民到了火星上。由于工业的需要,人们开始在火星上采矿。火星的矿区是一个边长为N的正六边形,为了方便规划,整个矿区被分为6*N*N个正三角形的区域(如图1)。
整个矿区中存在A矿,B矿,C矿三个矿场,和a厂,b厂,c厂三个炼矿厂。每个三角形的区域可以是一个矿场、炼矿厂、山地、或者平地。现在矿区管理局要求建立一个交通系统,使得矿场和对应炼矿厂之间存在一条公路,并且三条公路互不交叉(即一个三角形区域中不存在两条以上运输不同矿的公路)。两个三角形区域是相邻的当且仅当这两个三角形存在公共边,只有相邻的两个区域之间才能建一段路,建这段路的费用为1。注意,山地上是不能建公路的。由于火星金融危机的影响,矿区管理局想知道建立这样一个交通系统最少要花多少费用。更多的,当局向知道有多少种花费最小的方案。
Input
第1行一个整数N。表示这个矿区是边长为N的正六边形。
接下来有6*N*N的整数,分为2*N行,表示矿区当前区域的情况。0表示平地,1,2,3表示对应的矿区或者炼矿厂,4表示山地。(样例1对应图2)。可能有多组数据,请处理到文件结尾
Output
对于每组数据,包含两个整数,表示最小费用和达到最小费用的方案数。如果找不到符合要求的方案,输出-1 -1。由于方案数可能过大,所以请把方案数mod 1000000007
Sample Input
2
0 1 0 0 0
0 0 2 0 4 0 0
0 0 4 3 0 3 2
0 0 0 1 0
【样例输入2】
3
0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0 0
0 3 0 1 0 2 0
Sample Output
18 1
【样例输出2】
44 1
HINT
对于100%的数据,N≤6
const ss=;
const mo=;
const nn=;
var
b:array[..,..]of longint;
a:array[..,..,..,..,..,..]of boolean;
ax:array[..,..,..,..,..,..]of longint;
d:array[..nn]of longint;
g:array[..ss,..]of longint;
next,u:array[..nn,..]of longint;
f,w:array[..nn,..]of longint;
e:array[..nn,..]of boolean;
l,r,kk,qq,sx,sy,ii,jj,t1,t2,tt,i,j,n,m,k,t,x,y,z,p,q:longint;
procedure o(p,k,q,t:longint);
begin
ax[i,j,p,q,k,t]:=;
if (b[i+,j]<>)and(k<>b[i+,j])and(k<>) then exit;
if (b[i,j+]<>)and(t<>b[i,j+])and(t<>) then exit;
a[i,j,p,q,k,t]:=true;
if (p+k>)or((x>)and(x<)) then inc(ax[i,j,p,q,k,t]);
if (q+t>)or((y>)and(y<)) then inc(ax[i,j,p,q,k,t]);
end;
function hash(x,t:longint):longint;
var i:longint;
begin
if t=tt then
begin
i:=x mod ss+;
if u[g[i,t],t]=x then begin hash:=g[i,t]; g[i,t]:=next[g[i,t],t]; exit; end;
i:=g[i,t];
while u[next[i,t],t]<>x do i:=next[i,t];
hash:=next[i,t];
next[i,t]:=next[next[i,t],t]; exit;
end;
i:=g[x mod ss+,t];
while (i<>)and(u[i,t]<>x) do i:=next[i,t];
if u[i,t]=x then exit(i);
inc(t2); i:=x mod ss+; u[t2,t]:=x;
next[t2,t]:=g[i,t]; g[i,t]:=t2; exit(t2);
end;
begin
while true do
begin
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
fillchar(ax,sizeof(ax),);
readln(n); if eof then exit;
x:=n*+; m:=n*;
u[,]:=-; u[,]:=-;
for i:= to n+n+ do
for j:= to m+ do b[i,j]:=;
for i:= to n do
begin
for j:= to x do read(b[i,j]);
x:=x+;
end;
for i:=n+ to n+n do
begin
x:=x-;
for j:=m-x+ to m do read(b[i,j]);
end; n:=n*; readln;
for i:= to n do
for j:= to m do
if j and = then
begin
x:=b[i,j-]; y:=b[i,j];
if (x=)and(y=) then
begin
for p:= to do begin o(,,p,p); o(,p,p,); o(,p,,p); o(p,,,p); o(p,,p,); o(p,p,,); end;
for p:= to do for q:= to do o(p,p,q,q);
end else
if (x=)and(y<>) then
begin
for p:= to do begin o(p,p,y,); o(p,p,,y); end;
o(y,,,); o(,y,,);
end else
if (x=)and(y=) then
begin
for p:= to do o(p,p,,);
end else
if (x<>)and(y=) then
begin
for p:= to do begin o(x,,p,p); o(,x,p,p); end;
o(,,x,); o(,,,x);
end else
if (x<>)and(y<>) then
begin
o(x,,y,); o(x,,,y); o(,x,y,); o(,x,,y);
if x=y then o(,,,);
end else
if (x<>)and(y=) then
begin
o(x,,,); o(,x,,);
end else
if (x=)and(y=) then
begin
for p:= to do o(,,p,p);
end else
if (x=)and(y<>) then
begin
o(,,y,); o(,,,y);
end else o(,,,);
end;
for i:= to nn do
for j:= to do f[i,j]:=nn;
tt:=; i:=hash(,); tt:=;
f[i,]:=; w[i,]:=; e[i,]:=true;
l:=; r:=; t:=; p:=; q:=; kk:=; t1:=; t2:=;
while true do
begin
while true do
begin
k:=hash(d[l],tt);
if q= then d[l]:=d[l]*;
x:=(d[l]>>(q-))and ;
y:=(d[l]>>q)and ;
sx:=d[l]-x<<(q-)-y<<q;
for ii:= to do
for jj:= to do
if a[p,q,x,y,ii,jj] then
begin
qq:=sx+ii<<(q-)+jj<<q;
z:=hash(qq,kk);
if f[z,kk]>f[k,tt]+ax[p,q,x,y,ii,jj] then
begin
f[z,kk]:=f[k,tt]+ax[p,q,x,y,ii,jj];
w[z,kk]:=w[k,tt];
if not e[z,kk] then
begin
e[z,kk]:=true; d[t]:=qq; inc(t);
if t=nn then t:=;
end;
end else
if f[z,kk]=f[k,tt]+ax[p,q,x,y,ii,jj] then
begin
inc(w[z,kk],w[k,tt]);
if w[z,kk]>=mo then dec(w[z,kk],mo);
end;
end;
e[k,tt]:=false; w[k,tt]:=;
f[k,tt]:=nn;
if l=r then break;
inc(l); if l=nn then l:=;
end;
inc(l); if l=nn then l:=;
if l=t then break;
if t= then r:=nn- else r:=t-; tt:=kk; kk:=-kk; t1:=t2; t2:=;
if q=m then begin q:=; inc(p); end else inc(q,);
if p>n then break;
end;
i:=g[,tt];
while (i<>)and(u[i,tt]<>) do i:=next[i,tt];
if i= then writeln('-1 -1') else
begin
writeln(f[i,tt]-,' ',w[i,tt]);
end;
while l<>t do
begin
k:=hash(d[l],tt);
e[k,tt]:=false; w[k,tt]:=;
f[k,tt]:=nn;
if l=r then break;
inc(l); if l=nn then l:=;
end;
end;
end.
Caster
BZOJ2283: [Sdoi2011]火星移民的更多相关文章
- [Sdoi2011]火星移民
2283: [Sdoi2011]火星移民 Time Limit: 40 Sec Memory Limit: 512 MBSubmit: 119 Solved: 56[Submit][Status] ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 2243: [SDOI2011]染色 [树链剖分]
2243: [SDOI2011]染色 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6651 Solved: 2432[Submit][Status ...
- bzoj-2243 2243: [SDOI2011]染色(树链剖分)
题目链接: 2243: [SDOI2011]染色 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6267 Solved: 2291 Descript ...
- 【BZOJ2243】[SDOI2011]染色 树链剖分+线段树
[BZOJ2243][SDOI2011]染色 Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的 ...
- BZOJ 2286: [Sdoi2011]消耗战
2286: [Sdoi2011消耗战 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 2082 Solved: 736[Submit][Status] ...
- bzoj 2242: [SDOI2011]计算器 BSGS+快速幂+扩展欧几里德
2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 你被 ...
- 【BZOJ】【2245】【SDOI2011】工作安排
网络流/费用流 裸题吧……直接建模就好了……所谓的“分段函数”就是吓唬你的,其实就是对于每个人分开建几条流量不同.费用不同的弧而已. 对每种产品,连S->i ,(c[i],0):对每个工作人员 ...
- bzoj2243:[SDOI2011]染色
链剖就可以了.一开始的想法错了.但也非常接近了.妈呀调的要死...然后把字体再缩小一号查错起来比较容易QAQ. #include<cstdio> #include<cstring&g ...
随机推荐
- [luoguP1947] 笨笨当粉刷匠_NOI导刊2011提高(10)(DP)
传送门 f[i][j][k]表示前i行,最后一行前j个,选k次最优解 ntr[i][j][2]表示当前行区间i~j涂0或1所能刷的正确格子 #include <cstdio> #defin ...
- 【UOJ179】线性规划(单纯形)
题意: 思路:单纯形模板 ..,..]of double; idx,idy,q:..]of longint; c:..]of double; n,m,i,j,op,x,y:longint; eps,m ...
- 10.1——pair,map,set,multimap,multiset
map和set只允许相同的键出现一次,而multimap和multiset则允许出现多次. 1. 引言——pair类型: pair需要添加头文件utility头文件 make_pair<v1,v ...
- excludepathpatterns 无效
踩坑了,调了好久才调出来. 原因: 访问的API /XXX 已经转换为 /error 了. 把“/error” 也加入 excludepathpatterns 里面即可.
- springboot 第一个程序
idea --> new project --> 选择Spirng Initializr --> next 傻瓜式操作 --> 添加web依赖 项目基本结构: 创建contr ...
- response对象学习
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...
- TDBXJSONStream(BERLIN新增)的使用
DELPHI 10.1 BERLIN新增TDBXJSONStream类,用于方便地将数据序列为JSON,和将JSON还原出来数据. DATASNAP远程方法也相应地增加了支持返回TDBXJSONStr ...
- 多硬盘分区管理fdisk
原文:http://blog.fens.me/linux-fdisk/ ---------------------------------------------------------------- ...
- Cubieboard搭建Hadoop指南
1.刷固件 出厂的Cubieboard是Android系统,需要Linux系统安装Hadoop,到此网址下载: http://dl.cubieboard.org/software/a20-cubiet ...
- 碰撞检測之Sphere-Box检測
检測思路 首先要做的是将Box转为AABB,然后推断圆心是否在Box内.用的就是之前的SAT 假设圆心在Box内,肯定相交, 假设不在圆心内.则有四种情况,与顶点相交,与楞相交,与面相交,这里的确定也 ...