feeding time
来源:互联网 发布:如何作曲编曲软件 编辑:程序博客网 时间:2024/04/30 08:18
Feeding Time
Accepted : 16 Submit : 148Time Limit : 2000 MS Memory Limit : 1048576 KBIt's Bessie's feeding time, and Farmer John is trying to decidewhere to put her. FJ has a farm that comprises W x H (1 <= W <=750; 1 <= H <= 750) squares and is partitioned into one or moreseparate pastures by rocks both large and small. Every pasturecontains some grass and some rocks.Bessie is a hungry little cow and just loves to eat, eat, eat hergrass. She can move from any square to any other square that ishorizontally, vertically, or diagonally adjacent. Bessie can't crossthe rocks because they hurt her feet, and, of course, she can'tleave the farm. Bessie wants to know the maximum number of squaresof grass that she can eat.FJ has a map of his farm, where a '.' represents a square of grass,and a '*' represents a rock. Consider this 10x8 map and a detailedbreakdown of the extent of each of its three pastures: ...*....** | 111*....** ...*2222** ...*....** ..**....** | 11**....** ..**2222** ..**....** ...*....** | 111*....** ...*2222** ...*....** ...**.*.** | 111**.*.** ...**2*2** ...**.*.** ***.**.*** | ***1**.*** ***.**2*** ***.**.*** ...**.*.** | 111**.*.** ...**2*2** ...**.*.** ...*.***** | 111*.***** ...*2***** ...*.***** ...***..** | 111***..** ...***..** ...***33**Pasture 1 has 21 squares; pasture 2 has 18 squares; pasture 3 has2 squares. Thus Bessie should choose pasture 1 with 21 squares tomaximize the grass she can eat.THE PROBLEM CONTAINS MULTIPLE CASES.KEEP PROCESSING THE INPUT TILL EOF. INPUT FORMAT:
* Line 1: Two space-separated integers: W and H
* Lines 2..H+1: Line i+1 describes field row i with W characters (and no spaces), each either '.' or '*'
SAMPLE INPUT (file feedtime.in):
10 8...*....**..**....**...*....**...**.*.*****.**.***...**.*.**...*.*****...***..**
OUTPUT FORMAT:
* Line 1: A single integer that represents the maximum number of squares of grass that Bessie can eat.
SAMPLE OUTPUT (file feedtime.out):
21
Source
USACO FEB10广搜的非递归化。。。不解释
#include <stdio.h>#include <stack>#include <iostream>#include <stdlib.h>#include <vector>#include <string.h>using namespace std;char grid[755][755];int sign[755][755];int W, H,dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 },dy[] = { 0, 0, 1, -1, 1, 1, -1, -1 };stack<int> stx,sty;int main() { int x, y, nBest = 0, square,zx,zy,cx,cy; int sum; while(scanf("%d%d", &W, &H)!=EOF) { nBest=0; memset(sign,0,sizeof(sign)); for (y = 0; y < H; y++) scanf("%s", grid[y]); for (y = 0; y < H; y++) { for (x = 0; x < W; x++) { square=0; if(grid[y][x]!='*'&&sign[y][x]!=1) { stx.push(x); sty.push(y); sign[y][x]=1; while(!stx.empty()&&!sty.empty()) { cx=stx.top(); cy=sty.top(); stx.pop(); sty.pop(); square++; for (int i = 0; i < 8; i++) { zx=cx+dx[i]; zy=cy+dy[i]; if (!(zx < 0 || zx >= W || zy < 0 ||zy >= H || grid[zy][zx] == '*'||sign[zy][zx]!=0)) { stx.push(zx); sty.push(zy); sign[zy][zx]=1; } } } } if (square > nBest) nBest = square; } } printf("%d\n", nBest); } return 0;}
- feeding time
- sicily 2002 Feeding Time
- Sicily 2002. Feeding Time
- Sicily 2002 Feeding Time
- Sicily 2002. Feeding Time
- woj1007- Feeding Animals(I)
- WOJ1008-Feeding Animals(II)
- WOJ1007-Feeding Animals(I)
- hiho1227--The Cats' Feeding Spots
- 【HIHOCODER】The Cats' Feeding Spots
- Feeding Frenzy完成后的经验总结
- hihoCoder1227 The Cats' Feeding Spots 二分
- hihoCoder #1227 : The Cats' Feeding Spots
- hihoCoder 1227 The Cats' Feeding Spots(水)
- hihoCoder 1227 The Cats' Feeding Spots
- hihoCoder1227 The Cats' Feeding Spots【暴力】
- hihocoder #1227 : The Cats' Feeding Spots(枚举)
- time
- 115、sybase ec开发问题易犯问题
- Flash游戏存档文件 .sol文件替换+拷贝教程 附sol Editor下载
- 归并排序的简单算法
- 伯南克言辞模棱两可,美元先扬后抑
- 美制造迄今最大激光脉冲:500万亿瓦特功率
- feeding time
- MyEclipse7.5/8.5优化(其他版本可以类推)
- MDK + Jlink + SDRAM 裸奔2440教程
- Unity3D Mouse Position
- HDU 1171 Big Event in HDU
- WebLogic 11g start and stop automation
- DICOM相关软件
- gvim 图形化的 vim
- Flashback TABLE 实验