bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)
2017-09-16 23:58
573 查看
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 285 Solved: 192
[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 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
2C(25, 7) =
480700
放心的暴力吧
#include<stdio.h>
#include<string.h>
char str[7][7];
int ans, temp, c[8], d[8], flag[8];
int dir[4][2] = {1,0,0,1,-1,0,0,-1};
void Jud(int p)
{
int i, j, dx, dy;
flag[p] = 1, temp++;
for(i=0;i<=3;i++)
{
dx = c[p]+dir[i][0];
dy = d[p]+dir[i][1];
for(j=1;j<=7;j++)
{
if(c[j]==dx && d[j]==dy && flag[j]==0)
Jud(j);
}
}
}
void Sech(int x, int y)
{
int i, sum;
if(y==8)
{
temp = sum = 0;
memset(flag, 0, sizeof(flag));
for(i=1;i<=7;i++)
{
if(str[c[i]][d[i]]=='J')
sum++;
}
Jud(1);
if(sum>=4 && temp==7)
ans++;
return;
}
if(x>25)
return;
for(i=x;i<=25;i++)
{
c[y] = (i+4)/5;
d[y] = i-((i+4)/5-1)*5;
Sech(i+1, y+1);
}
}
int main(void)
{
int i;
for(i=1;i<=5;i++)
scanf("%s", str[i]+1);
Sech(1, 1);
printf("%d\n", ans);
return 0;
}
相关文章推荐
- 【BZOJ】1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力dfs+set判重)
- bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
- bzoj1675 [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 竞选划区(题解第一弹)
- bzoj1592 [Usaco2008 Feb]Making the Grade 路面修整
- 【BZOJ1713】[Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会 斜率优化
- BZOJ 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机
- BZOJ_1610_[Usaco2008_Feb]_Line连线游戏_(计算几何基础+暴力)
- 【bzoj1738】[Usaco2005 mar]Ombrophobic Bovines 发抖的牛 二分答案+最大流
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- BZOJ 1592 Usaco 2008 Feb Making the Grade 路面修整 DP
- bzoj 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 二分+最大流
- 【BZOJ】1653: [Usaco2006 Feb]Backward Digit Sums(暴力)
- [bzoj3061][Usaco13Feb]Partitioning the Farm_动态规划_状压dp
- BZOJ1736 [Usaco2005 jan]The Wedding Juicer 婚宴的榨汁机
- bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通(BFS)
- BZOJ 1738: [Usaco2005 mar]Ombrophobic Bovines 发抖的牛