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 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)

usaco良心网站,直接暴力不会挂……233
暴力枚举点就行了,每次枚举就在已经选到的点周围选就行咯,随手带几个剪枝。
至于去重,直接hash就好。在累计答案处hash:64MS,每一层搜索都hash(去掉重复扩展的状态)20MS,玩火人工二分MOD:44MS、48MS……
运气#1
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int MOD=;
int ans=,xx,yy,k;
int hash[MOD];
char c[][];
void dfs(int x,int y,int hn,int jn,int p){
if (x<||y<||x>||y>) return;
if (x<xx||(x==xx&&y<yy)) return;
if (c[x][y]=='H') hn++;else jn++;
if (hn>) return;
p+=<<((x*+y));
k=p%MOD;
while(hash[k]!=-){
if (hash[k]==p) return;
k++;
if (k>=MOD) k-=MOD;
}
hash[k]=p;
if (hn+jn==){
ans++;
return;
}
char s=c[x][y];
c[x][y]=;
for (int i=;i<;i++)
for (int j=;j<;j++)
if (c[i][j]==){
if (c[i+][j]!=) dfs(i+,j,hn,jn,p);
if (c[i-][j]!=) dfs(i-,j,hn,jn,p);
if (c[i][j+]!=) dfs(i,j+,hn,jn,p);
if (c[i][j-]!=) dfs(i,j-,hn,jn,p);
}
c[x][y]=s;
}
int main(){
for (int i=;i<;i++) scanf("%s",c[i]);
memset(hash,-,sizeof(hash));
for (xx=;xx<;xx++)
for (yy=;yy<;yy++) dfs(xx,yy,,,);
printf("%d\n",ans);
}
bzoj: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: ...
- 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.. 判重好 ...
- 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 ...
- BZOJ 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛( 二分答案 )
最小最大...又是经典的二分答案做法.. -------------------------------------------------------------------------- #inc ...
- bzoj 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
1734: [Usaco2005 feb]Aggressive cows 愤怒的牛 Description Farmer John has built a new long barn, with N ...
- [BZOJ 1733] [Usaco2005 feb] Secret Milking Machine 【二分 + 最大流】
题目链接:BZOJ - 1733 题目分析 直接二分这个最大边的边权,然后用最大流判断是否可以有 T 的流量. 代码 #include <iostream> #include <cs ...
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
Description 约翰正在制造一台新型的挤奶机,但他不希望别人知道.他希望尽可能久地隐藏这个秘密.他把挤奶机藏在他的农场里,使它不被发现.在挤奶机制造的过程中,他需要去挤奶机所在的地方T(1≤T ...
- bzoj:3392: [Usaco2005 Feb]Part Acquisition 交易
Description 奶牛们接到了寻找一种新型挤奶机的任务,为此它们准备依次经过N(1≤N≤50000)颗行星,在行星上进行交易.为了方便,奶牛们已经给可能出现的K(1≤K≤1000)种货物 ...
随机推荐
- 【java设计模式】【创建模式Creational Pattern】单例模式Singleton Pattern
//饿汉式:资源利用率较低(无论是否需要都会创建),性能较高(使用前无需判断实例是否存在,可直接使用) public class EagerSingleton{ private static fina ...
- js判断文件类型大小并给出提示
上传文件是工作中常用的功能,不同的场景对不同的文件类型和文件大小都有不同的要求: <form id="uploadForm" method="post" ...
- iOS 视频开发学习
原文:浅谈iOS视频开发 这段时间对视频开发进行了一些了解,在这里和大家分享一下我自己觉得学习步骤和资料,希望对那些对视频感兴趣的朋友有些帮助. 一.iOS系统自带播放器 要了解iOS视频开发,首先我 ...
- php项目报错 Warning: session_start(): open(D:/software/wamp/wamp/tmp\sess_msrjot7f32ciqb1p2hr4ahejg4, O_RDWR) f
今天一个php项目报错: Warning: session_start(): open(D:/software/wamp/wamp/tmp\sess_msrjot7f32ciqb1p2hr4ahejg ...
- css各种布局
1.水平居中 前提:父容器.parent 和子容器.child 1)使用text-align和inline-block .parent{text-aling:center}; .child {disp ...
- cat/tac/more/less 命令详解
cat:(http://www.cnblogs.com/peida/archive/2012/10/30/2746968.html) *cat主要有三大功能:1.一次显示整个文件:cat filena ...
- 设计模式之 - 策略模式(Strategy Pattern)
引入:项目中涉及到工作流,当然这个工作流的实现是由用户根据不同的策略或者说方式传入处理这个事件的人的审批链,后台在存储过程中进行解析,然后生成最终的审批链,在系统中流转进行审批. 比如审批链: 张三 ...
- UWP 使用OneDrive云存储2.x api(二)【全网首发】
接上一篇 http://www.cnblogs.com/hupo376787/p/8032146.html 上一篇提到为了给用户打造一个完全无缝衔接的最佳体验,UWP开发者最好也要实现App设置和数据 ...
- Jmeter 创建FTP测试计划
FTP服务主要提供上传和下载功能. 操作步骤: 1.创建一个线程组 2.线程组--->添加--->配置元件--->FTP请求缺省值:输入服务器名称或IP. 3.线程组--->添 ...
- Python第二十一天 fileinput模块
Python第二十一天 fileinput模块 fileinput模块 fileinput.input([files[, inplace[, backup[, bufsize[, mode[, ...