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 ...
随机推荐
- 抓包分析YY音频
YY的音频数据传输是P2P协议,音频的编码为AAC,下面抓去的音频编码的信息和频谱信息. 音频编码为AAC,采样为44K,码率24kb/s.音频编码在24kb/s码率能达到15K的音质.值得大家学习啊 ...
- doubango(5)--SIP协议栈传输层的启动
SIP协议的INVITE消息发起流程 当通过sip协议发起一个会话时,需要通过invite消息实现该流程.而SIP协议是一个基于事务的协议,每一个sip会话的都是通过sip部件间的一系列消息来完成的. ...
- mac下sublime 配置查看源码
sublime及package control的安装查看之前一篇文章:http://www.cnblogs.com/xdwa/p/5805101.html 安装ctags 安装完毕package co ...
- 进阶之初探nodeJS
一.前言 在"初探nodeJS"随笔中,我们对于node有了一个大致地了解,并在最后也通过一个示例,了解了如何快速地开启一个简单的服务器. 今儿,再次看了该篇随笔,发现该随笔理论知 ...
- EmitMapper 和TinyMapper 两者简单对比
EmitMapper 和TinyMapper 两者的性能都是很高,相比autoMapper 速度不知道快了多少倍,因为使用的最多EmitMapper,所在业余时间做了一下测试对比. 测试数据:10万条 ...
- web开发的性能准则(减少页面加载时间方面)
准则(概述) 减少 HTTP 请求 使用CDN加速 避免空的src或href属性值 增加过期头 启GZIP压缩 把css文件放到头部 把javascript放到尾部 避免使用css表达式 删除不使用的 ...
- C++编程练习(16)----“排序算法 之 快速排序“
快速排序 基本思想: 通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序的目的. 算法介绍: 设要排序的 ...
- WinForm——记住密码
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runti ...
- 智能指针shared_ptr
// 智能指针会自动释放所指向的对象. // shared_ptr的应用场景是:程序需要在多个对象间共享数据 /* 先从应用场景入手吧,说矿工A发现了一个金矿. * 然后矿工A喊来了矿工B,一起开采, ...
- DOM范围
前面的话 为了让开发人员更方便地控制页面,DOM定义了“范围”(range)接口.通过范围可以选择文档中的一个区域,而不必考虑节点的界限(选择在后台完成,对用户是不可见的).在常规的DOM操作不能更有 ...