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枚举位置判可行性也能过啊……

我服了

  1. #include<cstdio>
  2. const int mx[4]={0,1,0,-1};
  3. const int my[4]={1,0,-1,0};
  4. bool map[6][6];
  5. int d[6][6];
  6. int s[8];
  7. int nx[8],ny[8];
  8. int q[10];
  9. int ans;
  10. inline bool mark()
  11. {
  12. int i,j,sx,sy,xx,yy,sum=0,t=0,w=1;
  13. for (i=1;i<=5;i++)for(j=1;j<=5;j++)d[i][j]=0;
  14. for (i=1;i<=7;i++)
  15. {
  16. ny[i]=s[i]%5;nx[i]=s[i]/5;
  17. if (ny[i])nx[i]++;
  18. if (!ny[i])ny[i]=5;
  19. d[nx[i]][ny[i]]=i;
  20. }
  21. q[1]=1;d[nx[1]][ny[1]]=0;sum=map[nx[1]][ny[1]];
  22. while (t<w)
  23. {
  24. xx=nx[q[++t]];
  25. yy=ny[q[t]];
  26. for (int k=0;k<4;k++)
  27. {
  28. sx=xx+mx[k];sy=yy+my[k];
  29. if (sx>0&&sy>0&&sx<6&&sy<6&&d[sx][sy])
  30. {
  31. q[++w]=d[sx][sy];
  32. d[sx][sy]=0;
  33. sum+=map[sx][sy];
  34. }
  35. }
  36. }
  37. return w==7&&sum>3;
  38. }
  39. int main()
  40. {
  41. for (int i=1;i<=5;i++)
  42. for (int j=1;j<=5;j++)
  43. {
  44. char ch=getchar();
  45. while (ch!='H'&&ch!='J')ch=getchar();
  46. if (ch=='J')map[i][j]=1;
  47. }
  48. for (s[1]=1;s[1]<=19;s[1]++)
  49. for (s[2]=s[1]+1;s[2]<=20;s[2]++)
  50. for (s[3]=s[2]+1;s[3]<=21;s[3]++)
  51. for (s[4]=s[3]+1;s[4]<=22;s[4]++)
  52. for (s[5]=s[4]+1;s[5]<=23;s[5]++)
  53. for (s[6]=s[5]+1;s[6]<=24;s[6]++)
  54. for (s[7]=s[6]+1;s[7]<=25;s[7]++)
  55. if (mark())ans++;
  56. printf("%d",ans);
  57. }

  

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. 完整的多项匹配tomcat access日志的正则

    <pre name="code" class="html"><pre name="code" class="ht ...

  2. c# list exists(contains) delegate 委托判断 元素是否在LIST中存在

    static void Main(string[] args)        {            List<GoodsInfo> list = new List<GoodsIn ...

  3. Search for a Range 解答

    Question Given a sorted array of integers, find the starting and ending position of a given target v ...

  4. 四种简单的排序算法的php实现

    无聊,用php写几个排序算法,算法介绍请移步这里,这里使用php实现了几个简单的,如下 //选择排序 function selection_sort($arr){ $len = count($arr) ...

  5. Git服务器搭建全过程

    GitHub是一个免费托管开源代码的Git服务器,如果我们不想公开项目的源代码,又不想付费使用,那么我们可以自己搭建一台Git服务器. 下面我们就看看,如何在Ubuntu上搭建Git服务器.我们使用V ...

  6. Hive 10、Hive的UDF、UDAF、UDTF

    Hive自定义函数包括三种UDF.UDAF.UDTF UDF(User-Defined-Function) 一进一出 UDAF(User- Defined Aggregation Funcation) ...

  7. Linux usb子系统(一):子系统架构

    一.USB协议基础知识   前序:USB概念概述 USB1.0版本速度1.5Mbps(低速USB) USB1.1版本速度12Mbps(全速USB)  USB2.0版本速度480Mbps(高速USB). ...

  8. IOS UIImage 模糊

    #import <UIKit/UIKit.h> #import <Accelerate/Accelerate.h> #import <QuartzCore/QuartzC ...

  9. AE分级渲染

    分级渲染classbreakrenderer位于carto类库中,进行分级渲染时,首先要将相应图层按照某一Field分级.可使用esrisystem类库中的iclassifyGEN类的classify ...

  10. .net中用到的一些方法

    //文件操作string fullDirPath = Utils.GetMapPath(string.Format("/aspx/{0}/", buildPath)); Direc ...