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

暴力出奇迹啊……

直接7个for枚举位置判可行性也能过啊……

我服了

#include<cstdio>
const int mx[4]={0,1,0,-1};
const int my[4]={1,0,-1,0};
bool map[6][6];
int d[6][6];
int s[8];
int nx[8],ny[8];
int q[10];
int ans;
inline bool mark()
{
int i,j,sx,sy,xx,yy,sum=0,t=0,w=1;
for (i=1;i<=5;i++)for(j=1;j<=5;j++)d[i][j]=0;
for (i=1;i<=7;i++)
{
ny[i]=s[i]%5;nx[i]=s[i]/5;
if (ny[i])nx[i]++;
if (!ny[i])ny[i]=5;
d[nx[i]][ny[i]]=i;
}
q[1]=1;d[nx[1]][ny[1]]=0;sum=map[nx[1]][ny[1]];
while (t<w)
{
xx=nx[q[++t]];
yy=ny[q[t]];
for (int k=0;k<4;k++)
{
sx=xx+mx[k];sy=yy+my[k];
if (sx>0&&sy>0&&sx<6&&sy<6&&d[sx][sy])
{
q[++w]=d[sx][sy];
d[sx][sy]=0;
sum+=map[sx][sy];
}
}
}
return w==7&&sum>3;
}
int main()
{
for (int i=1;i<=5;i++)
for (int j=1;j<=5;j++)
{
char ch=getchar();
while (ch!='H'&&ch!='J')ch=getchar();
if (ch=='J')map[i][j]=1;
}
for (s[1]=1;s[1]<=19;s[1]++)
for (s[2]=s[1]+1;s[2]<=20;s[2]++)
for (s[3]=s[2]+1;s[3]<=21;s[3]++)
for (s[4]=s[3]+1;s[4]<=22;s[4]++)
for (s[5]=s[4]+1;s[5]<=23;s[5]++)
for (s[6]=s[5]+1;s[6]<=24;s[6]++)
for (s[7]=s[6]+1;s[7]<=25;s[7]++)
if (mark())ans++;
printf("%d",ans);
}

  

bzoj1675 [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. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)

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

  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. 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)

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

  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. 安全:加固你的ssh 登录

    SSH 是我们控制虚拟主机的一种途径,这个途径可以让我们拥有完全的控制权,如果对于这个控制权没有进行很好的安全处理,那么将会造成很大的安全问题.      我们可以在系统的日志文件 (例如:/var/ ...

  2. 【剑指offer】面试题26:复杂链表的复制

    题目: 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点). 思路: 复制自身到下一个结点: 设置新结点的random指针: 分离链表. 注意:判 ...

  3. 使用skin++进行MFC界面美化范例

    1.下载skin++皮肤库和皮肤库,skin++皮肤库主要包括:SkinPPWTL.dll,SkinPPWTL.lib,SkinPPWTL.h这三个文件.把这三个文件 拷贝到工程目录下. 2.在工程中 ...

  4. Eclipse 里的 Classpath Variables M2_REPO 无法修改(maven)

      解决方法: 在C:\Documents and Settings\Administrator\.m2中放入setting.xml,并修改本地仓库为 <localRepository>D ...

  5. Java里多个Map的性能比較(TreeMap、HashMap、ConcurrentSkipListMap)

    问题 比較Java原生的 1.  TreeMap 2.  HashMap 3.  ConcurrentSkipListMap 3种Map的效率. 结果 模拟150W以内海量数据的插入和查找,通过添加和 ...

  6. Android资源--颜色RGB值以及名称及样图

      颜  色    RGB值 英文名 中文名   #FFB6C1 LightPink 浅粉红   #FFC0CB Pink 粉红   #DC143C Crimson 深红/猩红   #FFF0F5 L ...

  7. vim的正则表达式(二)应用实例

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  8. CoutDownLatch 多线程同步辅助类

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 主要方法 public CountDownLatch(int count); pu ...

  9. 在[self addsubView:xxx]中,self.name 和 _name的区别

    在[self addsubView:xxx]中,self.name 和 _name的区别self.name 会调用重写的getter方法,而_name添加的只是_name 这个成员变量

  10. UIScrollView 代理方法

    在使用UIScrollView和它的子类UITableView时,有时需要在不同操作状态下,做不同的响应. 如何截获这些状态,如正在滚动,滚动停止等,使用UIScrollViewDelegate_Pr ...