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.

    5行,输入农场的情况.

Output

* Line 1: The number of distinct districts of 7 connected cows such that the Jerseys outnumber the Holsteins in the district.

    输出划区方案总数.

Sample Input

HHHHH
JHJHJ
HHHHH
HJHHJ
HHHHH

Sample Output

2

HINT

Source

题解:一开始这道题我看了半天硬是没敢做,首先想到的是状压DP,可是状压虽然25格应该能压得下,但是怎么判断连续?所以一时束手无策
直到看到了某位网上的神犇说——大力出奇迹!!!orzorzorz
然后我就按照那样子来了一发,结果居然能A!!!神奇QAQ
实际上就是\( O\left( {25}^{7} \right) \)的朴素暴力,实在没想到这都能AC,于是有种瞬间被彻底吓尿的感觉QAQ
但是很明显有很大优化的空间,于是本人打算明天再来一发强化版的么么哒(现已完成,传送门
 
 /**************************************************************
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 竞选划区(题解第一弹)的更多相关文章

  1. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  2. 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1675 一开始我写了个枚举7个点....... 但是貌似... 写挫了. 然后我就写dfs.. 判重好 ...

  3. 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 ...

  4. 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 ...

  5. 问题 L: 「Usaco2005 Feb」竞选划区O(∩_∩)O 纯属的暴力

    题目描述 农场被划分为5x5的格子,每个格子中都有一头奶牛,并且只有荷斯坦(标记为H)和杰尔西(标记为J)两个品种. 如果一头奶牛在另一头上下左右四个格子中的任一格里,我们说它们相连. 奶牛要大选了. ...

  6. BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易

    3392: [Usaco2005 Feb]Part Acquisition 交易 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 26  Solved:  ...

  7. BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )

    最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...

  8. 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

    1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 217  Solved: ...

  9. bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛

    1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...

随机推荐

  1. KingbaseES的standby搭建

    KingbaseES数据库部署及双机热备配置 Dataguard双机热备部署 注:配置期间使用数据库的属主用户进行操作 1.1 数据一致性准备 (1)修改数据库的配置文件参数:(2阶段初始化的数据库实 ...

  2. WPF dataGrid中的check的改变事件

    关于datagrid信息: <DataGridTemplateColumn Header="备注"> <DataGridTemplateColumn.CellTe ...

  3. js json和字符串的互转

    json与字符串的互转:    下面格式两种只是针对引号有稍微的区别 var result = JSON.parse("{\"a\":\"擦擦\",\ ...

  4. Wireshark网络抓包(三)——网络协议

    一.ARP协议 ARP(Address Resolution Protocol)地址解析协议,将IP地址解析成MAC地址. IP地址在OSI模型第三层,MAC地址在OSI第二层,彼此不直接通信: 在通 ...

  5. ADO.NET 扩展属性、配置文件 和 对战游戏

    扩展属性 有外键关系时将信息处理成用户可看懂的 利用扩展属性 如:Info表中的民族列显示的是民族代号处理成Nation表中的民族名称 需要在Info类里面扩展一个显示nation名称的属性 例:先前 ...

  6. 从jvm的角度来看java的多线程

    最近在学习jvm,发现随着对虚拟机底层的了解,对java的多线程也有了全新的认识,原来一个小小的synchronized关键字里别有洞天.决定把自己关于java多线程的所学整理成一篇文章,从最基础的为 ...

  7. 笔记之《用python写网络爬虫》

    1 .3 背景调研 robots. txt Robots协议(也称为爬虫协议.机器人协议等)的全称是"网络爬虫排除标准"(Robots Exclusion Protocol),网站 ...

  8. Javascript的简单测试环境

    在<JavaScript忍者秘籍>2.4测试条件基础知识中,作者给出了一个精简版的assert和assert组的实现,对于初学者而言,这无疑是一个很好的例子,既让我们得到了一个好用的小工具 ...

  9. Android Studio中.9.png文件出错问题

    昨天使用别人的.9.png图片放在自己的android studio工程下使用,出现如下错误: :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DA ...

  10. 快速排序的C语言实现

    #include <stdio.h> int qSort(int a[],int i,int j) { int h = i; int r = j; int x = a[h]; int f ...