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
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 ...
随机推荐
- DNS信息
主机A记录: 描述主机地址记录,在dns域名和ip地址之间建立映射关系语法: owner class ttl A IP_v4_address eg: host1.example.mircrosoft. ...
- 细说WPF数据绑定
简单的事例: <Slider Name="mySlider" Height="28" HorizontalAlignment="Left&q ...
- PowerDesigner如何把建好的表导入到数据库中,并且把注释也导入进去
第一次接触这个软件,经过自己的捣鼓和百度,终于可以顺利的导入数据库中了,好开森,希望可以帮助到更多人. 数据库(mysql)其实和sqlserver差不多,以16.5版本为例 1.选中一个PDM项目, ...
- python enhanced generator - coroutine
本文主要介绍python中Enhanced generator即coroutine相关内容,包括基本语法.使用场景.注意事项,以及与其他语言协程实现的异同. enhanced generator 在上 ...
- 【js 编程艺术】小制作三
1.html文件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- Ubuntu 16.04安装配置Samba服务
Samba是开源软件,用来让Linux系统与Windows系统的SMB/CIFS网络协定做连结,实现Windows主机与Linux服务器之间的资源共享.Samba服务为两种不同的操作系统架起了一座桥梁 ...
- jQuery的拾色器
代码如下 1.js <link href="css/farbtastic.css" rel="stylesheet" /> <script t ...
- spring和UEditor结合
前言 春节无聊,就去弄一下富文本编辑器,然后百度了一番,很多说百度的UEditor不错,然后去官网照着文档弄一遍,是挺简单好用的.然后想把这玩意结合到自己的一个spring项目里面,果然还是在点上传图 ...
- Zore copy(翻译《Efficient data transfer through zero copy》)
原文:https://www.ibm.com/developerworks/library/j-zerocopy/ <Efficient data transfer through zero c ...
- Java程序测试之线程的使用
package thread_test; class A implements Runnable { public void run() { while(true) { System.out.prin ...