Bucket Brigade//水题//排位2

2023-10-28 03:58
文章标签 bucket 水题 排位 brigade

本文主要是介绍Bucket Brigade//水题//排位2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Bucket Brigade//水题//排位2


题目

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: [Math Processing Error] 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
The input file contains 10 rows each with 10 characters, describing the layout of the farm.

Output
Output a single integer giving the minimum number of cows needed to form a viable bucket brigade.

Example
inputCopy



…B…

…R…


…L…

outputCopy
7

题意
从B到L,绕过R,求最短距离

思路

水题,特判三点在同一直线即可

代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#define pi 3.1415926
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
char s[20][20];
int sx,sy,ex,ey,ans=999999;
int rx,ry;
int main(){memset(s,0,sizeof(s));for(int i=1;i<=10;i++)scanf("%s",s[i]+1);for(int i=1;i<=10;i++){for(int j=1;j<=10;j++){if(s[i][j]=='B'){sx=j;sy=i;}if(s[i][j]=='L'){ex=j;ey=i;}if(s[i][j]=='R'){rx=j;ry=i;}}}int d1=abs(sx-rx)+abs(sy-ry);int d2=abs(ex-rx)+abs(ey-ry);ans=abs(sx-ex)+abs(sy-ey);if((sx==ex||sy==ey)&&(ans==d1+d2))ans+=2;printf("%d\n",ans-1);return 0;
}

注意

处理好二分边界

这篇关于Bucket Brigade//水题//排位2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/290523

相关文章

uva 10055 uva 10071 uva 10300(水题两三道)

情歌两三首,水题两三道。 好久没敲代码了为暑假大作战热热身。 uva 10055 Hashmat the Brave Warrior 求俩数相减。 两个debug的地方,一个是longlong,一个是输入顺序。 代码: #include<stdio.h>int main(){long long a, b;//debugwhile(scanf("%lld%lld", &

Codeforces Round #182 (Div. 2)A(水题)

题目链接:http://codeforces.com/contest/302/problem/A 解题思路: 只要通过重新排列使区间内和为0即是1,否则是0. 完整代码: #include <algorithm>#include <iostream>#include <cstring>#include <complex>#include <cstdio>#inc

HDU 2064 汉诺塔III(水题)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=2064 题目大意: 有三根杆,求把n个圆盘从左边移到右边,最少需要移动圆盘的次数。移动规则为大盘不能放在小盘上,比原始的汉诺塔题改变的地方是,只能通过中间的杆往左右两边的杆移动。 心得: 此题心得在题外,不在题内,初看此题,尼玛吓了一跳,好像很难的样子,手贱百度了一下,只注意到俩字“水题”,赶紧

【SGU】115. Calendar 水题= =

传送门:【SGU】115. Calendar 题目分析:2001年1月1号星期1,然后就没什么好说的了= = 代码如下: #include <map>#include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespac

常用的限流算法-令牌桶(Token Bucket)php版

令牌桶(Token Bucket)是一种常用的限流算法,用于控制流量的速率。其核心思想是以固定速率向桶中放入令牌,当请求到来时,从桶中取走一定数量的令牌,如果桶中没有足够的令牌,则拒绝请求或进行排队等待。 下面是如何在 PHP 中实现一个简单的令牌桶算法。 1. 令牌桶的基本概念 令牌的生成速度:令牌以固定速率生成并加入到桶中。桶的容量:桶中可以容纳的最大令牌数,防止令牌无限增长。请求的消耗

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)

解题报告 意思就是说有n行柜子,放奖杯和奖牌,要求每行柜子要么全是奖杯要么全是奖牌,而且奖杯每行最多5个,奖牌最多10个。 直接把奖杯奖牌各自累加,分别出5和10,向上取整和N比较 #include <iostream>#include <cstdio>#include <cstring>#include <stdlib.h>#include <algorithm>

ElasticSearch学习笔记(五)Bucket聚合、Metric聚合

文章目录 前言9 项目实战9.3 我周边的酒店9.4 酒店竞价排名 10 数据聚合10.1 聚合的分类10.2 DSL实现聚合10.2.1 Bucket聚合10.2.2 聚合结果排序10.2.3 限定聚合范围10.2.4 Metric聚合 10.3 RestAPI实现聚合10.3.1 API语法10.3.2 业务需求10.3.3 业务实现10.3.4 功能测试 前言 Elas

hdu 1013(水题)

题意:求一个数,各个数位相加,如果结果小于10则输出,否者递归进行数位相加。   #include <cstdio>#include <cstring>#include <string>#include <iostream>using namespace std;int result(int n){int sum = 0;while (n > 0){sum += n % 1

HDU 1008(水题)

题意:给一个数n,后跟着n个数,代表电梯要到的层数,如果是上升,则每层花费6分钟,下降每层划分4分钟,停着话费5分钟,求电梯总共花费多少时间。   #include <iostream>using namespace std;void main(){int n, m, t, total;while (cin >> n && n != 0){m = 0;total = 0;wh

HDU 1001(水题)

题意:输入n,求1~n之和。 import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner s=new Scanner(System.in);int n=0;int sum;while(s.hasNextInt()){sum=0;n=s.nextInt();