bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
2014-08-05 22:57
417 查看
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 createa 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
HHHHHJHJHJ
HHHHH
HJHHJ
HHHHH
Sample Output
2HINT
![](http://www.lydsy.com:808/JudgeOnline/upload/201401/44(3).jpg)
暴力出奇迹啊……
直接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); }
相关文章推荐
- 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)
- bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
- bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)
- bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 (暴力)
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)
- 【BZOJ】1687: [Usaco2005 Open]Navigating the City 城市交通(bfs)
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典
- BZOJ1652 [Usaco2006 Feb]Treats for the Cows
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- BZOJ1753 [Usaco2005 qua]Who's in the Middle
- bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算
- BZOJ3392: [Usaco2005 Feb]Part Acquisition 交易
- BZOJ 1592: [Usaco2008 Feb]Making the Grade 路面修整
- 【BZOJ】1652: [Usaco2006 Feb]Treats for the Cows(dp)
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛
- 【BZOJ】3392: [Usaco2005 Feb]Part Acquisition 交易(spfa)