求助!!!USACO2019年3月份铜级第一题

题目

A fire has broken out on the farm, and the cows are rushing to try and put it out!

The farm is described by a 10×10

grid of characters like this:




…B…

…R…


…L…

The character ‘B’ represents the barn, which has just caught on fire. The ‘L’ character represents a lake, and ‘R’ represents the location of a large rock.

The cows want to form a “bucket brigade” by placing themselves along a path between the lake and the barn so that they can pass buckets of water along the path to help extinguish the fire. A bucket can move between cows if they are immediately adjacent in the north, south, east, or west directions. The same is true for a cow next to the lake — the cow can only extract a bucket of water from the lake if she is immediately adjacent to the lake. Similarly, a cow can only throw a bucket of water on the barn if she is immediately adjacent to the barn.

Please help determine the minimum number of ‘.’ squares that should be occupied by cows to form a successful bucket brigade.

A cow cannot be placed on the square containing the large rock, and the barn and lake are guaranteed not to be immediately adjacent to each-other.

INPUT FORMAT (file buckets.in):
The input file contains 10 rows each with 10 characters, describing the layout of the farm.

OUTPUT FORMAT (file buckets.out):
Output a single integer giving the minimum number of cows needed to form a viable bucket brigade.

SAMPLE INPUT:




…B…

…R…


…L…

SAMPLE OUTPUT:

7

In this example, here is one possible solution, which involves the optimal number of cows (7):




…B…
…C…
…CC.R…
…CCC…
…C…
…L…

Problem credits: Brian Dean

我的代码

#include<bits/stdc++.h>
using namespace std;
int ddd();
char ma[11][11];
char ans[11][11];
int wzh[11][11];
int shortest[9];
int main(){
	freopen("buckets.in","r",stdin);
    freopen("buckets.out","w",stdout);
    
for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	    cin>>ma[i][j];
    }
}//初始化输入 

for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	    if(ma[i][j]=="R")
	    wzh[i][j]=1;
	    if(ma[i][j]=="L")
	    wzh[i][j]=2;
	    if(ma[i][j]=="B")
	    wzh[i][j]=3;
    }
}//解析地图 

for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	    if(wzh[i][j]=2){
	    	ddd(i,j);
		}
    }
}//分析最短路径 

for(int i=0;i<10;i++){
	if(shortest[i]>shortest[i+1])
	shortest[i+1]=shortest[i];
}//判断哪条路径最短 
cout<<shortest[9];//输出
 
return 0;
} 
int ddd(i,j){
	if(wzh[i][j]==3){
		return ;
	}
	else{
	if(wzh[i+1][j]==0){
		shortest[0]+=1;
		return ddd(i+1,j);
	}
	if(wzh[i+1][j+1]==0){
		shortest[1]+=1;
		return ddd(i+1,j+1);
	}
	if(wzh[i+1][j-1]==0){
		shortest[2]+=1;
		return ddd(i+1,j-1);
	}
    if(wzh[i][j+1]==0){
	    shortest[3]+=1;
		return ddd(i,j+1);
	}
	if(wzh[i][j-1]==0){
	   shortest[4]+=1;
		return ddd(i,j-1);
	}
	if(wzh[i-1][j+1]==0){
        shortest[5]+=1;
		return ddd(i-1,j+1);
	}
	if(wzh[i-1][j]==0){
	    shortest[6]+=1;
		return ddd(i-1,j);
	}
	if(wzh[i-1][j-1]==0){
	    shortest[7]+=1;
		return ddd(i-1,j-1);
	}

感想

错了无所谓,但是不知道错哪儿就很严重了。还请各位大神求助!!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值