NOI2009植物大战僵尸
这题应该分两步来做:
1、拓扑排序,去掉无敌点
2、求最大闭合子图
需要注意几点:
1、拓扑排序时,如果(i,j)可以攻击到(x,y),那么增加(x,y)的入度,而不是(i,j)的入度
因为入度代表着要攻击它需要事先攻击几个点
2、求最大闭合子图时,用所有的正权点-最大流
3、求最大闭合子图时,如果(i,j)可以攻击到(x,y),那么连一条边(x,y)到(i,j),容量为正无穷
因为在最大闭合子图中边(x,y)到(i,j)意味着选(x,y)就必须要选(i,j),这与实际含义相符
4、s到正权点,容量为正权点的点权
负权点到t,容量为负权点的点权的绝对值
5、要做好对数据规模的估计
代码:
- type node=record
- go,next,c:longint;
- end;
- var e:array[..] of node;
- head,tail,i,n,m,j,tot,max,ans,s,t,x,y:longint;
- w,cur,first,inp,q,h:array[..] of longint;
- can:array[..] of boolean;
- a:array[..,..] of longint;
- procedure insert(x,y,z:longint);
- begin
- inc(tot);
- e[tot].go:=y;
- e[tot].c:=z;
- e[tot].next:=first[x];
- first[x]:=tot;
- inc(tot);
- e[tot].go:=x;
- e[tot].c:=;
- e[tot].next:=first[y];
- first[y]:=tot;
- end;
- function min(x,y:longint):longint;
- begin
- if x<y then exit(x) else exit(y);
- end;
- procedure init;
- begin
- readln(n,m);
- fillchar(inp,sizeof(inp),);
- for i:= to n*m do
- begin
- read(w[i]);read(a[i,]);
- for j:= to a[i,] do
- begin
- read(x,y);inc(x);inc(y);
- a[i,j]:=(x-)*m+y;
- inc(inp[(x-)*m+y]);
- end;
- if i mod m<> then
- begin
- inc(a[i,]);a[i,a[i,]]:=i-;inc(inp[i-]);
- end;
- readln;
- end;
- end;
- procedure topsort;
- begin
- head:=;tail:=;
- fillchar(q,sizeof(q),);
- fillchar(can,sizeof(can),false);
- for i:= to n*m do
- if inp[i]= then
- begin
- can[i]:=true;inc(tail);q[tail]:=i;
- end;
- while head<tail do
- begin
- inc(head);
- x:=q[head];
- for i:= to a[x,] do
- begin
- y:=a[x,i];
- dec(inp[y]);
- if inp[y]= then
- begin
- can[y]:=true;
- inc(tail);
- q[tail]:=y;
- end;
- end;
- end;
- end;
- procedure makegraph;
- begin
- max:=;
- for i:= to n*m do
- if can[i] then
- begin
- if w[i]> then inc(max,w[i]);
- for j:= to a[i,] do
- begin
- y:=a[i,j];
- if can[y] then insert(y,i,maxlongint>>);
- end;
- if w[i]> then insert(s,i,w[i])
- else insert(i,t,-w[i]);
- end;
- end;
- function bfs:boolean;
- var i,x,y:longint;
- begin
- fillchar(h,sizeof(h),);
- fillchar(q,sizeof(q),);
- head:=;tail:=;q[]:=s;h[s]:=;
- while head<tail do
- begin
- inc(head);
- x:=q[head];
- i:=first[x];
- while i<> do
- begin
- y:=e[i].go;
- if (h[y]=) and (e[i].c<>) then
- begin
- h[y]:=h[x]+;
- inc(tail);
- q[tail]:=y;
- end;
- i:=e[i].next;
- end;
- end;
- exit(h[t]<>);
- end;
- function dfs(x,f:longint):longint;
- var i,y,tmp,used:longint;
- begin
- if (x=t) or (f=) then exit(f);
- i:=cur[x];tmp:=;used:=;
- while i<> do
- begin
- y:=e[i].go;
- if (h[y]=h[x]+) and (e[i].c<>) then
- begin
- tmp:=dfs(y,min(e[i].c,f-used));
- dec(e[i].c,tmp);
- inc(e[i xor ].c,tmp);
- if e[i].c<> then cur[x]:=i;
- inc(used,tmp);
- if used=f then exit(f);
- end;
- i:=e[i].next;
- end;
- if used= then h[x]:=-;
- exit(used);
- end;
- procedure dinic;
- begin
- while bfs do
- begin
- for i:= to n*m+ do cur[i]:=first[i];
- inc(ans,dfs(s,maxlongint>>));
- end;
- end;
- procedure main;
- begin
- tot:=;
- s:=;t:=n*m+;
- topsort;
- makegraph;
- dinic;
- writeln(max-ans);
- end;
- begin
- init;
- main;
- end.
NOI2009植物大战僵尸的更多相关文章
- 图论(网络流):COGS 410. [NOI2009] 植物大战僵尸
410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:pvz.out 简单对比时间限制:2 s 内存限制:512 MB [问题描述] Plants vs ...
- P2805 [NOI2009]植物大战僵尸
题目地址:P2805 [NOI2009]植物大战僵尸 最大权闭合子图 若有向图 \(G\) 的子图 \(V\) 满足: \(V\) 中顶点的所有出边均指向 \(V\) 内部的顶点,则称 \(V\) 是 ...
- COGS410. [NOI2009] 植物大战僵尸
410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:pvz.out 简单对比时间限制:2 s 内存限制:512 MB [问题描述] Plants vs ...
- BZOJ 1565: [NOI2009]植物大战僵尸
1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2317 Solved: 1071[Submit][Stat ...
- 【刷题】BZOJ 1565 [NOI2009]植物大战僵尸
Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻. ...
- 【bzoj1565】[NOI2009]植物大战僵尸
1565: [NOI2009]植物大战僵尸 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2164 Solved: 1001[Submit][Stat ...
- 【最大权闭合子图 tarjan】bzoj1565: [NOI2009]植物大战僵尸
dinic+tarjan板子练手题 Description Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其 中P ...
- BZOJ1565: [NOI2009]植物大战僵尸
Description Input Output 仅包含一个整数,表示可以获得的最大能源收入.注意,你也可以选择不进行任何攻击,这样能源收入为0. Sample Input 3 2 10 0 20 0 ...
- 【bzoj1565】 NOI2009—植物大战僵尸
http://www.lydsy.com/JudgeOnline/problem.php?id=1565 (题目链接) 题意 给出$n*m$的棋盘,僵尸攻击每个格子可以获得$v$的分数,每个格子又会保 ...
- luogu2805 [NOI2009]植物大战僵尸
想象一下,要搞掉一个植物,必须先搞掉另一些植物--我们可以发现这是一个最大权闭合子图的问题. 最大权闭合子图的话,太空飞行计划问题是一个入门题,可以一看. 然而我们手玩一下样例就会惊恐地发现,保护关系 ...
随机推荐
- 处理部分WordPress核心代码或功能,让你的网站更快
处理部分WordPress核心代码或功能,让你的网站更快 http://www.wpdaxue.com/speed-up-wordpress.html
- Spark Streaming揭秘 Day34 解析UI监听模式
Spark Streaming揭秘 Day34 解析UI监听模式 今天分享下SparkStreaming中的UI部分,和所有的UI系统一样,SparkStreaming中的UI系统使用的是监听器模式. ...
- HDFS知识体系 思维导图
- css 面试学习
最经在学习前端的一些东西 转载于http://www.cnblogs.com/lei2007/archive/2013/08/16/3262897.html 雅虎的css前端的35条定律
- Oracle回收站
回收站是删除对象使用的存储空间.可以使用实例参数recyclebin禁用回收站,默认是on,可以为某个会话或系统设置为off或on.所有模式都有一个回收站. 当表空间不足时可以自动重用回收站对象占用的 ...
- Delaunay三角剖分
Bowyer-Watson算法:1.假设已经生成了连接若干个顶点的Delaunay三角网格:2.加入一个新的节点,找出所有外接圆包含新加入节点的三角形,并将这些三角形删除形成一个空洞:3.空洞的节点与 ...
- [转]控制反转(IOC)和依赖注入(DI)
http://blog.csdn.net/Elite_1989/article/details/16851565 控制反转和依赖注入可以理解成同一个东西,都是为解耦而生的~ 控制反转(IoC=Inve ...
- 1042: [HAOI2008]硬币购物 - BZOJ
Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法.Input 第一行 ...
- [machine learning] Loss Function view
[machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function? ...
- spoj 1436
用并查集看一下是否会围成一个环 若围成环直接输出NO 当然 当 m >= n 时必然会围成环直接输出NO #include <algorithm> #include < ...