1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 196 Solved: 116
[Submit][Status][Discuss]
Description
It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of which holds either a Holstein ('H') or Jersey ('J') cow. The Jerseys want to create a voting district of 7 contiguous (vertically or horizontally) cow locations such that the Jerseys outnumber the Holsteins. How many ways can this be done for the supplied grid?
农场被划分为5x5的格子,每个格子中都有一头奶牛,并且只有荷斯坦(标记为H)和杰尔西(标记为J)两个品种.如果一头奶牛在另一头上下左右四个格子中的任一格里,我们说它们相连. 奶牛要大选了.现在有一只杰尔西奶牛们想选择7头相连的奶牛,划成一个竞选区,使得其中它们品种的奶牛比荷斯坦的多. 要求你编写一个程序求出方案总数.
Input
* Lines 1..5: Each of the five lines contains five characters per line, each 'H' or 'J'. No spaces are present.
Output
* Line 1: The number of distinct districts of 7 connected cows such that the Jerseys outnumber the Holsteins in the district.
Sample Input
JHJHJ
HHHHH
HJHHJ
HHHHH
Sample Output
HINT
.jpg)
Source
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ const
mx:array[..] of longint=(,,,-);
my:array[..] of longint=(,,-,);
var
i,j,k,l,m,n,ans,i1,i2,i3,i4,i5,i6,i7:longint;
ch:char;
map:array[..,..] of longint;
s:array[..] of longint;
function check:boolean;
var
i,j,sx,sy,xx,yy,sum,t,w:longint;
nx,ny:array[..] of longint;
q:array[..] of longint;
d:array[..,..] of longint;
begin
sum:=;t:=;w:=;
fillchar(nx,sizeof(nx),);
fillchar(ny,sizeof(ny),);
fillchar(q,sizeof(q),);
fillchar(d,sizeof(d),);
for i:= to do
begin
ny[i]:=s[i] mod ;
nx[i]:=(s[i] div )+;
if ny[i]= then
begin
ny[i]:=;
dec(nx[i]);
end;
d[nx[i],ny[i]]:=i;
end;
q[]:=;d[nx[],ny[]]:=;sum:=map[nx[],ny[]];
while t<w do
begin
inc(t);
xx:=nx[q[t]];
yy:=ny[q[t]];
for k:= to do
begin
sx:=xx+mx[k];
sy:=yy+my[k];
if (sx<) or (sy<) or (sy>) or (sy>) or (d[sx,sy]=) then continue;
inc(w);
q[w]:=d[sx,sy];
d[sx,sy]:=;
inc(sum,map[sx,sy]);
end;
end;
exit((w=) and (sum>));
end;
begin
fillchar(map,sizeof(map),);
for i:= to do
for j:= to do
begin
read(ch);
if ch='J' then map[i,j]:= else map[i,j]:=;
if j= then readln;
end;
ans:=;
for i1:= to do
for i2:=i1+ to do
for i3:=i2+ to do
for i4:=i3+ to do
for i5:=i4+ to do
for i6:=i5+ to do
for i7:=i6+ to do
begin
s[]:=i1;s[]:=i2;s[]:=i3;
s[]:=i4;s[]:=i5;s[]:=i6;s[]:=i7;
if check then inc(ans);
end;
writeln(ans);
readln;
end.
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)的更多相关文章
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)
http://www.lydsy.com/JudgeOnline/problem.php?id=1675 一开始我写了个枚举7个点....... 但是貌似... 写挫了. 然后我就写dfs.. 判重好 ...
- bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...
- bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...
- 问题 L: 「Usaco2005 Feb」竞选划区O(∩_∩)O 纯属的暴力
题目描述 农场被划分为5x5的格子,每个格子中都有一头奶牛,并且只有荷斯坦(标记为H)和杰尔西(标记为J)两个品种. 如果一头奶牛在另一头上下左右四个格子中的任一格里,我们说它们相连. 奶牛要大选了. ...
- BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易
3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 26 Solved: ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
- 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 217 Solved: ...
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...
随机推荐
- 其实想要完全理解MVC框架并不是太容易
完全理解MVC并不是很容易.使用MVC需要精心的计划,由于它的内部原理比较复杂,所以需要花费一些时间去思考.同时由于模型和视图要严格的分离,这样也给调试应用程序带来了一定的困难.每个构件在使用之前都需 ...
- validform表单验证插件最终版
做个笔记,以后直接用吧. 报名界面: <%@ page language="java" pageEncoding="UTF-8" contentType= ...
- mybatis判断集合为空或者元素个数为零
mybatis判断集合为空或者元素个数为零: <if test="mlhs != null and mlhs.size() != 0"> and t.mlh_name ...
- Servlet3.1规范和JSP2.3规范
JSR 340: Java Servlet 3.1 Specification https://jcp.org/en/jsr/detail?id=340 http://files.cnblogs.co ...
- java服务器获取客户端ip
在写服务端代码时,有时需要对客户端ip做认证,比如限制只有某些ip能访问,或者1个ip1天只能访问几次.最近就碰到个需要限制ip的情况,从网上找了一些服务器获取客户端ip的方法,说的都不太完善,这里整 ...
- Excel实用知识3
纯手打,可能有错别字,使用的版本是office2013 转载请注明出处 http://www.cnblogs.com/hnnydxgjj/p/6343914.html ,谢谢 数据透视表 数据透视表是 ...
- Redis key 相关命令
其实本质上,Redis 就是一个Key---Value 数据库.这里我先介绍下Redis中关于的key的相关命令, 注意:key是字符串存储,但是不能使用 空格 或者 “\n”,value 则可以使用 ...
- html 一般标签 常用标签 表格
body的属性: bgcolor 页面背景色 background 背景壁纸.图片 text 文字颜色 top ...
- node Express安装与使用(一)
首先放上官网地址 http://www.expressjs.com.cn/ 学会查阅官方手册,它是最好的资料. 1.Express安装 首先确定你已经安装了 Node.js,然后去你创建的项目目录下( ...
- Windows Container 和 Docker:你需要知道的5件事
微软在2016年的Ignite技术大会上正式发布了Windows Server 2016,其中的容器服务已经可以作为生产环境使用.这意味着Windows 内置的容器服务正式进入了大家的视野,虽然之前我 ...