UCF 2021 Qualifying - H . Time to Eat + UCF HSPT 2020 - E . Use Giant Fans to Deal With Hurricanes?

article/2025/8/18 23:02:20
题目:

H . Time to Eat [ 问题 8933 ] [ 讨论 ]
Description
The UCF Programming Team has made it to the World Contest Finals (WF), thanks to the great team members and coaches. Fortunately for Dr. Orooji (Team Faculty Advisor), WF is in a city with streets running only horizontally and vertically (this means the chance of Dr. O getting lost is less). The city can be described as a two-dimensional grid with R rows and C columns. The team hotel is at the upper-left corner (cell with indices 1, 1). The contest will be at the bottom-right corner (cell with indices R,C).

The UCF group will start at the hotel and needs to be at the contest site. From a cell, the group can walk into one of the four neighboring cells (north, south, east, west). Note that the cells on the boundary do not have four neighbors. The group would like to make it to the contest with the fewest number of steps – moving from a cell to a neighboring cell is considered taking a step.

One complication with the trip from the hotel to the contest site is that the UCF group gets hungry and needs to eat after they’ve taken certain number of steps. For example, if they have to eat after taking 10 steps, then their 10th step (or an earlier step) must walk them into a cell with food (sub shop).

The need to eat means the group may not be able to take the shortest path from the hotel to the contest site because the sub shops may not be on that path. Fortunately, there are enough sub shops at different spots (cells) such that the group can eat when needed and make it to the contest site, though they may take a few extra steps than the straight path from the hotel to the contest site.

The Problem:

Given the description of the city, determine the minimum number of steps needed for the UCF group to go from their hotel to the contest site, taking into account that they need to eat after taking certain number of steps (or before taking that many steps if a sub shop is not exactly at that position on the path).

Input
The first input line contains four integers: R (1≤R≤50), indicating the number of rows in the grid, C (1≤C≤50), indicating the number of columns in the grid, F (1≤F≤100), indicating the number of steps the group can take and then need to eat, and S (1≤S≤100), indicating the number of sub shops in the grid.

Each of the next S input lines contains two integers (1≤r≤R, 1≤c≤C) providing the row and column number for a sub shop. Assume that all sub shops are at different locations and they are not at the hotel or contest site.

Output
Print the minimum number of steps needed for the UCF group to go from their hotel to the contest site.

Samples
Input 复制
10 6 5 7
1 6
5 4
8 1
9 1
8 3
10 1
2 5
Output
18

Input 复制
5 10 5 3
1 5
2 7
5 6
Output
13

题意:有一个团队需要从地图的左上角走到右下角,这个团队有一个体力值,每走一步会掉一点体力值,在体力值消耗完前需要去商店里吃东西补充体力值,最后走到右下角,问团队最少需要走的步数。(保证在体力值消耗完前能找到一个商店)
输入:给定地图的长R和宽C,团队的体力值F,商店的个数S,接下来S行每行一个坐标
输出:团队从左上角到右下角需要的最少步数
思路:一看到最少步数就可以想到最优,最短之类的词语,一般这种题就要用到BFS,所以这道题就是一个有点新奇的BFS。
// The past is irrevocable and the future can be changed.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int m,n,k,s,x,y;
int a[111][111];
int dir[6][6]= {{1,0},{-1,0},{0,1},{0,-1}};
map< pair<pair<int,int>, pair<int,int> >,bool> mp;
struct ss{  //存团队状态的结构体 int x,y;int tl;int step;
}pre;
int dfs(){queue<ss>q;  //开一个队列存团队在走到每一个点的状态 q.push(pre);mp[{{pre.x,pre.y},{pre.step,pre.tl}}]=1;//防止重复推入一样的情况导致内存超限 while(q.size()){ss fir=q.front();if(fir.x==m&&fir.y==n)  //如果走到终点就返回团队走的步数 return fir.step;q.pop();for(int i=0;i<4;i++){ss sec;int dx=fir.x+dir[i][0];int dy=fir.y+dir[i][1];if(dx>=1&&dx<=m&&dy>=1&&dy<=n&&fir.tl>0){ //pre.tl>0防止体力等于零后又走到商店回满体力 if(a[dx][dy])  //如果走到商店,补满体力 sec.tl=k;else           //否则减一点体力 sec.tl=fir.tl-1;sec.x=dx,sec.y=dy,sec.step=fir.step+1; //更新状态if(sec.tl>=0){   //如果此时体力大于等于零,将此时的状态存入队列 if(mp[{{sec.x,sec.y},{sec.step,sec.tl}}]==0){//防止重复推入一样的情况导致内存超限q.push(sec);mp[{{sec.x,sec.y},{sec.step,sec.tl}}]=1;}} 	}		//cout<<sec.x<<" "<<sec.y<<" "<<sec.tl<<" "<<sec.step<<" "<<"|"<<endl;}}
}
int main(){cin>>m>>n>>k>>s;pre.x=1,pre.y=1,pre.tl=k,pre.step=0; //初始化团队最初的状态 for(int i=1;i<=s;i++){cin>>x>>y;a[x][y]=1;}int res=dfs();cout<<res;return 0;
}
相似题目:UCF HSPT 2020 - E . Use Giant Fans to Deal With Hurricanes?
题目:E . Use Giant Fans to Deal With Hurricanes? [ 问题 8006 ] [ 讨论 ]

Description
The Earth is under attack by Aliens! Anybody who has watched the movie “Signs” knows that Aliens are weak to water. In a last ditch effort to save humanity, the world military has cornered the Aliens on an island and set up giant fans on big aircraft carriers surrounding it.

The island can be represented as a square n×n grid. There are three types of cells. Cells with no Aliens on them are denoted by ‘W’ (water) or ‘L’ (land). An Alien’s position is represented by the letter ‘A’. Since it is an island, the borders of the grid are guaranteed to be water cells.
在这里插入图片描述
The military arranges their four fans facing north, south, east, and west, and can only activate one at a time. When a fan activates, it pushes all Aliens one cell in that direction. If an Alien is pushed into water, it instantly drowns. Aliens do not move unless a fan is activated. They just stand there. Menacingly.

While the world is facing an existential threat, the military still wishes to conserve energy in order to prevent another existential threat in the form of climate change. For this reason, you have been hired to find the minimum number of times a fan needs to be activated to kill all Aliens.

The Problem:

Determine the minimum number of times a fan must be activated in order to kill all Aliens.

Input
The first line of the input will begin with a single positive integer, t, representing the number of scenarios. For each scenario, multiple lines will follow. The first line contains a single integer, n (3≤n≤10), representing the dimensions of the island. Then, on the following lines there are n rows each consisting of n characters, as described in above, describing the state of the island. It is guaranteed that there is at least one alien.

Output
For each scenario, output a single line with an integer representing the minimum number of fan activations.

Samples
Input 复制
3
8
WWWWWWWW
WALLLLLW
WLWWLLLW
WLLWLWLW
WLALLALW
WWLLLLLW
WLLLLLAW
WWWWWWWW
4
WWWW
WLAW
WAWW
WWWW
3
WWW
WAW
WWW

Output
2
1
1

题意:给一个N*N的地图,里面有一些外星人,还有一些水池,外星人掉入水池里就会死亡 ,现在你有一个超级风扇,每次可以把所有的外星人向 上下左右其中一个方向吹走一步,最后把所有的外星人都吹入池塘,问你最少需要多少次操作可以把外星人都干掉。
思路:这个题跟上面那个很相似,也是一个特别的BFS,不过这个题目中队列里存的是每个外星人的状态。
//The sunrise in the east reminds people to wake up, less than the sunset knows my heart
#include<bits/stdc++.h>
using namespace std;
int n;
char s[101][101];
int dir[6][6]= {{1,0},{-1,0},{0,1},{0,-1}};
struct node {vector< pair<int,int> >p;  //记录所有外星人的坐标! (在上个题目里面用的是 x和 y,区别不大) int step;  //记录我们操作的步数! int num;  //记录当前外星人的存活数量!
} Node;
int bfs() {queue<node> q;q.push(Node);while(q.size()) {node now=q.front();if(now.num==0)return now.step;q.pop();for(int i=0; i<4; i++) {  //遍历每个方向!node new_node;for(int j=0; j<now.p.size(); j++) {int dx=now.p[j].first+dir[i][0];int dy=now.p[j].second+dir[i][1];if(s[dx][dy]!='W'&&dx>=1&&dx<=n&&dy>=1&&dy<=n) {new_node.p.push_back({dx,dy});}}new_node.step=now.step+1;new_node.num=new_node.p.size();q.push(new_node);}}
}
int main() {int t;cin>>t;for(int i=1; i<=t; i++) {Node.p.clear();cin>>n;for(int j=1; j<=n; j++)for(int k=1; k<=n; k++) {cin>>s[j][k];if(s[j][k]=='A') {Node.p.push_back({j,k});}}Node.step=0;Node.num=Node.p.size();int ans=bfs();cout<<ans;if(i!=t)cout<<endl;}return 0;
}

http://chatgpt.dhexx.cn/article/YBef1cvp.shtml

相关文章

MTU

MTU 是出接口方向的MTU值,跟入接口方向无关。 MTU 是双方向的,也就是说两个方向的数据流可以有不同的MTU值。 在实施中遇到这么个问题: 用户在BigIP的VLAN设置中修改了MTU值,并保存。但系统重启后,这个值又恢复为原来的默认值了。 有兄弟遇到过么?望指点一二。 [ 本帖最…

Mahout学习

Mahout学习 Mahout学习&#xff08;主要学习内容是Mahout中推荐部分的ItemCF、UserCF、Hadoop集群部署运行&#xff09; 1、Mahout是什么&#xff1f; Mahout是一个算法库,集成了很多算法。 Apache Mahout 是 Apache Software Foundation&#xff08;ASF&#xff09;旗下的…

metahuman 简介

目录 metahuman 简介 metahuman是什么登陆metahuman人物导出 metahuman 简介 metahuman是什么 是一个像游戏的捏脸软件&#xff0c;是云端的。在开始之前我们需要注册一个epic的账号 epic是一个白嫖游戏的网页&#xff0c;引擎&#xff0c;商城&#xff0c;metahuman都是他们做…

CTFHub | .htaccess

0x00 前言 CTFHub 专注网络安全、信息安全、白帽子技术的在线学习&#xff0c;实训平台。提供优质的赛事及学习服务&#xff0c;拥有完善的题目环境及配套 writeup &#xff0c;降低 CTF 学习入门门槛&#xff0c;快速帮助选手成长&#xff0c;跟随主流比赛潮流。 0x01 题目描述…

C++手敲基于梯度图和像素数量数组的OTSU阈值分割

一、OTSU算法原理 ➢OTSU法&#xff08;最大类间方差法&#xff0c;有时也称之为大津算法&#xff09; ➢ 使用聚类的思想&#xff0c;把图像的灰度数按灰度级分成2个部分&#xff0c; 使得两个部分之间的灰度值差异最大&#xff0c;每个部分之间的灰 度差异最小 ➢ 通过方差…

Otsu图像分割

opencv自带Otsu算法&#xff0c;只需要在分割时将参数选择为“cv2.THRESH_OTSU”即可 #coding:utf-8 import cv2 import numpy as np from matplotlib import pyplot as pltimage cv2.imread(E:/shale10053.bmp) grayimage cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) gray c…

OpenCV中图像的自适应处理、Otsu方法讲解与实战(附Python源码)

需要源码请点赞关注收藏后评论区留言私信~~~ 一、自适应处理 很多时候图像色彩是不均衡的&#xff0c;如果只使用一种阈值处理类型&#xff0c;就无法得到清晰有效的结果 下面使用五种常用的阈值处理类型对色彩不均衡的图像进行处理 代码如下 import cv2image cv2.imread(&…

图像分割 - 阈值处理 - 多阈值处理(OTSU)

目录 1. 多阈值处理介绍 2. 代码讲解 3. 完整代码 1. 多阈值处理介绍 之前介绍的都是全局单个阈值对图像的分割。固定阈值法&#xff0c;阈值是人工根据灰度直方图的波谷进行设置的。全局阈值法&#xff0c;根据不停的迭代两个区域间的平均灰度进行分割。OUST最大类间方差法…

otsu算法详细推导、实现及Multi Level OTSU算法实现

otsu算法详细推导、实现及Multi Level OTSU算法实现 微信公众号&#xff1a;幼儿园的学霸 目录 文章目录 otsu算法详细推导、实现及Multi Level OTSU算法实现目录简介推导及实现常规推导算法步骤及实现步骤实现 从概率的角度解释推导实现 扩展-MultiLevel OTSU延伸思考算法评价…

OTSU算法及其改进算法学习

这篇文章还是来自斯坦福课后作业hw2_3&#xff0c;主要是结合一个例子介绍otsu算法【亦称为大律算法&#xff0c;小日本】及其改进算法。 本文将先介绍老外的题目、解题思路及maltab解答&#xff0c;然后分析otsu算法步骤&#xff0c;末了给出opencv实现。 老外的题目&#xff…

Otsu Thresholding

1. Otsu Thresholding Explained Otsu对image中的所有像素都假定为阈值&#xff0c;然后根据此值将image分为前景物体和背景&#xff1b;遍历所有像素值 计算类内方差&#xff0c;最小的类内方差对应的threshold即为最优阈值&#xff1b; 以6阶灰度图像为例 A 6-level greys…

Otsu算法原理及实现

在图像处理中Otsu方法&#xff0c;是以 Nobuyuki otsu 的名字命名的&#xff08;日本人&#xff0c;大津展之&#xff09;&#xff0c;常用于基于图像分割的聚类。该算法的理论依据是&#xff1a;假定图像包含两类像素&#xff08;前景像素和背景像素&#xff09;&#xff0c;直…

10 Otsu 算法

文章目录 前言一、Otsu 是什么&#xff1f;二、算法实验1.使用第三方库2.不使用第三方库 前言 Otsu 是一种利用图像的灰度特征自动计算二值化阈值的方法&#xff0c;常被称为 Otsu 自动阈值法。 使用 Otsu 方法可以避免主观性和繁琐性的阈值选取操作&#xff0c;并能够在一定…

OTSU(最大类间方差法、大津算法)

OTSU是阈值分割中一种常用的算法&#xff0c;它可以根据图像自动生成最佳分割阈值。OTSU的核心思想是类间方差最大化。 import cv2 import numpy as np from matplotlib import pyplot as pltimage cv2.imread("2.bmp") gray cv2.cvtColor(image, cv2.COLOR_BGR2G…

Bootstrap模态框里 再弹模态框

Bootstrap模态框里 再弹模态框 后端代码点击编辑 按钮 将参数赋值隐藏 input 中 , 便于修改 获取对应id修改模态框详情模态框 后端代码 /*** 财务审核使用详情** param request* param id* return*/RequestMapping(params "getUseDatil")ResponseBodypublic JSONAr…

新增模态框

平时我们在VS中也常常会用到模态框&#xff0c;今天我们就来聊聊模态框&#xff0c;但是我要说的是新增模态框&#xff0c;而不是修改模态框喔。在书写模态框代码时&#xff0c;我们还要引用一个插件: 然后就可以进行对代码进行书写了。 我们先说说模态框插件的用法&#xff0c…

html模态框常见问题,模态框无法弹出的问题

问题起因&#xff1a; 昨晚写到了一个模态框&#xff0c;用到了bootstrap和jquery&#xff0c;依赖的js已经复制到项目中&#xff0c;并在Jsp页面上进行了引用&#xff0c;最初的引用如下&#xff1a; 问题描述&#xff1a; 模态框无法正常弹出&#xff0c;使用浏览器查看资源看…

Vue模态框的封装

一、模态框 1、模态框&#xff1a;若对话框不关闭&#xff0c;不能操作其父窗口 2、非模态框&#xff1a;对话框不关闭&#xff0c;可以操作其窗口 二、Vue组件实现模态框的功能 1、模态框是一个子组件 2、显示和隐藏由父组件决定 3、对话框的标题也是由父组件传递的 4、对话框…

Bootstrap之模态框

前言 模态框&#xff08;Modal&#xff09;是覆盖在父窗体上的子窗体。通常&#xff0c;目的是显示来自一个单独的源的内容&#xff0c;可以在不离开父窗体的情况下有一些互动。子窗体可提供信息、交互等。 用法 您可以切换模态框&#xff08;Modal&#xff09;插件的隐藏内…

php什么是模态框,bootstrap模态框有什么用

Bootstrap Modals(模态框)是使用定制的Jquery 插件创建的。 它可以用来创建模态窗口丰富用户体验&#xff0c;或者为用户添加实用功能。您可以在 Modals(模态框)中使用 Popover(弹出框)和 Tooltip(工具提示插件)。(推荐学习&#xff1a;Bootstrap视频教程) 将通过一些实例和解释…