3018: [Usaco2012 Nov]Distant Pastures
3018: [Usaco2012 Nov]Distant Pastures
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 43 Solved: 20
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
(((
()(
(()
Sample Output
样例说明
左上角到右下角所需的时间为5,是最大值。
数据范围
100%的数据满:1 <= n <= 30,1 <= A <= 1,000,000,1 <= B <= 1,000,000。
HINT
Source
题解:本来一开始想到的是floyd暴力乱搞,但是在这里面复杂度是O(N^6)的,显然爆(HansBug:更何况这么稀疏的图这么玩不挂才怪= =)
于是根据囧神(HansBug:orzJSZKC)的做法,开始枚举起点玩spfa,于是居然很神奇的AC了QAQ(HansBug:我去这都能A,不过再一看N<=30也就懂了^_^)
(PS:我居然成了继囧神以后第一个Pascal秒掉此题的人了么么哒)
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g,w:longint;
next:point;
end;
var
i,j,k,l,m,n,x,y,f,r:longint;
a:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
b:array[..,..] of longint;
ch:char;p:point;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
function trans(x,y:longint):longint;
begin
exit((x-)*n+y);
end;
procedure add(x,y,z:longint);
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
new(p);p^.g:=x;p^.w:=z;p^.next:=a[y];a[y]:=p;
end;
procedure spfa(z:longint);
var i,j,f,r:longint;p:point;
begin
fillchar(g,sizeof(g),);
fillchar(c,sizeof(c),-);
d[]:=z;f:=;r:=;g[z]:=;c[z]:=;
while f<r do
begin
p:=a[d[f]];
while p<>nil do
begin
if (c[p^.g]=-) or (c[p^.g]>(c[d[f]]+p^.w)) then
begin
c[p^.g]:=c[d[f]]+p^.w;
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;inc(f);
end;
for i:= to n do for j:= to n do l:=max(l,c[trans(i,j)]);
end; begin
readln(n,x,y);
for i:= to n*n do a[i]:=nil;
for i:= to n do
begin
for j:= to n do
begin
read(ch);
case ch of
'(':b[i,j]:=;
')':b[i,j]:=;
end;
end;
readln;
end;
for i:= to n do
for j:= to n do
begin
if i<n then add(trans(i,j),trans(i+,j),abs(b[i,j]-b[i+,j])*(y-x)+x);
if j<n then add(trans(i,j),trans(i,j+),abs(b[i,j]-b[i,j+])*(y-x)+x);
end;
l:=;
for i:= to n*n do spfa(i);
writeln(l);
readln;
end.
3018: [Usaco2012 Nov]Distant Pastures的更多相关文章
- BZOJ3016: [Usaco2012 Nov]Clumsy Cows
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 71 Solved: 52[Submi ...
- 3016: [Usaco2012 Nov]Clumsy Cows
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 91 Solved: 69[Submi ...
- 【BZOJ】3016: [Usaco2012 Nov]Clumsy Cows(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3016 之前yy了一个贪心,,,但是错了,,就是枚举前后对应的字符(前面第i个和后面第i个)然后相同答 ...
- BZOJ 3016 [Usaco2012 Nov]Clumsy Cows:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3016 题意: 给你一个括号序列,问你至少修改多少个括号,才能使这个括号序列合法. 题解: ...
- [Usaco2012 Nov]Concurrently Balanced Strings
Description [Brian Dean, 2012] Farmer John's cows are all of a very peculiar breed known for its dis ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ USACO 银组 水题集锦
最近刷银组刷得好欢快,好像都是水题,在这里吧他们都记录一下吧(都是水题大家一定是道道都虐的把= =)几道比较神奇的题到时再列出来单独讲一下吧= =(其实我会说是BZOJ蹦了无聊再来写的么 = =) [ ...
- Usaco2012-2013 金组 题解 (暂缺Hill walk以及Figue eight)
https://files.cnblogs.com/files/Winniechen/usaco2012-2013.pdf 做的不是很好,还请见谅! 如果有什么疑问,可以QQ上找我. QQ号:1967 ...
随机推荐
- Oracle 表空间迁移
迁移表空间databump 使用databump导入导出,两个库用户必须一致,否则另一个库导入的时候会报错.所以两个库都是用helei用户. 给两个数据库的用户分别授予dba权限,这里只是实验更清晰而 ...
- Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]
环境为Spring + Spring mvc + mybatis:其中Spring版本为4.1.4 spring配置文件: <?xml version="1.0" encod ...
- SQL2008实现数据库自动定时备份——维护计划
在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求管理员 每天守到晚上1点去备份数据库.要实现数据库的 ...
- python中关于字符串的操作
Python 字符串操作方法大全 python字符串操作实方法大合集,包括了几乎所有常用的python字符串操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下 1. ...
- HDU5835
Danganronpa Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 服务器部署项目出现问题:Unsupported major.minor version 52.0
问题描述: 编写一个web 前置服务,使用ant编译项目,将项目部署到服务器上,启动时报此错误:Unsupported major.minor version 52.0 网上给出错误原因是服务器安装的 ...
- Sublime Text3常用插件以及安装方法(实用)
Package Control组件在线安装 按Ctrl+`调出console(注:避免热键冲突) 粘贴以下代码到命令行并回车: import urllib.request,os; pf = 'Pack ...
- python之列表对象
1. 获取列表中的某个值 描述:获取下标所对应的值 语法: print(li[0]) #[取索引值] 样例: li = list(['a','b','c']) val=(li[0]) #获取下标所对应 ...
- 基于Ubuntu14.04-LTS下安装docker
1.sudo apt-get update --更新系统源 2.sudo apt-get install docker.io 3.将docker库的公钥中加入到本地apt中 sudo apt-key ...
- Vue.js的环境搭建
vue这个新的工具,确实能够提高效率,vue入门的精髓:(前提都是在网络连接上的情况下) 1.要使用vue来开发前端框架,首先要有环境,这个环境要借助于node,所以要先安装node,借助于node里 ...