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 ...
随机推荐
- JS-鼠标滚轮事件 和 阻止默认行为
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Debian8 安装wordpress博客
首先要安装 php5-gd 已保证wordpress可以正常安装 下载Wordpress wget http://wordpress.org/latest.tar.gz 解压 tar -xzvf la ...
- gunicorn 简介
gunicorn是一个python Wsgi http server,只支持在Unix系统上运行,来源于Ruby的unicorn项目.Gunicorn使用prefork master-worker ...
- Word常用实用知识3
纯手打,可能有错别字,使用的版本是office Word 2013 转载请注明出处 http://www.cnblogs.com/hnnydxgjj/p/6322813.html,谢谢. 分页符分页 ...
- 如何使用矩阵乘法加速动态规划——以[SDOI2009]HH去散步为例
对这个题目的最初理解 开始看到这个题,觉得很水,直接写了一个最简单地动态规划,就是定义 f[i][j]为到了i节点路径长度为j的路径总数, 转移的话使用Floyd算法的思想去转移,借助这个题目也理解了 ...
- POJ2115(扩展欧几里得)
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23700 Accepted: 6550 Descr ...
- 作为测试人员,我是这么报BUG的
在测试人员提需求的时候,大家经常会看到,测试员和开发一言不合就上BUG.然后开发一下就炸了,屡试不爽,招招致命. 曾经看到有个段子这么写道: 不要对程序员说,你的代码有BUG. 他的第一反应是:1.你 ...
- 王爽汇编语言(第三版)环境搭建(附PDF及工具下载)
一.前言 最近在学习汇编语言,使用的是读者评价非常高的王爽老师写的<汇编语言>(第三版),为了适应现在各个版本的windows操作系统,所以采用VMWare虚拟机来搭建纯DOS环境. 二. ...
- IOS获取经度纬度
仔细研究了一下SDK文档,再结合网上的方法,写了这一个简单的获取经纬度的方法,大家看看就好. 首先要导入CoreLocation.Frame 包 .h 文件 1 2 3 4 5 6 7 8 9 #im ...
- github在windows下的安装和基本使用
1.在win下安装github时花费的时间是非常长的,有时还会出现因各种原因安装不成功.离线包本地安装方便的解决了此问题.点击http://pan.baidu.com/s/1boGrNLP可下载,解压 ...