题目:

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;
}

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

  1. 2021年儋州市高考成绩查询,儋州召开2020年高考中考总结会暨2021年高考中考动员会...

    新海南客户端.南海网.南国都市报11月5日消息(记者 李绍远)11月5日,儋州市教育局召开2020年高考中考总结会暨2021年高考中考动员会.会议对2020年儋州高考中考结果进行总结分析,并对2021 ...

  2. ucf 转xdc_如何用vivado将ucf转成xdc

    匿名用户 1级 2017-07-16 回答 很高兴告诉你! 自从去年10月Xilinx发布ISE147之后,ISE套件便暂时没有了更新计划,相当于进入了软件生命中的"中年":而当初 ...

  3. ICPC 2021上海 H Life is a Game

    kruskal重构树的题目,一开始没想好怎么建图觉得好烦,最后发现用struct自定义节点node代码就清晰多了. #include <bits/stdc++.h> using names ...

  4. 曙光中学2021年高考成绩查询,上海市部分高中2020高考录取喜报,成绩喜人!

    日前,自主选拔在线团队整理2020年全国各中学清华北大录取人数汇总,帮助考生了解清华北大今年在各省.中学录取情况,今天整理上海市中学2020年高考录取情况,不得不说,尽管2020年多坎坷,但是这一届的 ...

  5. 东北育才高中2021年高考成绩查询,东北育才学校2020年高考成绩喜报

    1 清华北大等重点高校2020年在京录取分数线汇总 录取分数线对考生和家长来说尤为重要,2020年是北京高考改革元年,在没有任何数据可参考的情况下,2020年的各高校在北京的录取分数线对2021届考生 ...

  6. 2021高考数学成绩查询,吐血整理!2020高考数学评分细则参考,2021高考这样准备少丢分!...

    高考大题秉承按步骤作答.按步骤给分的原则,哪些步骤是有分可拿的?哪些步骤是可以省略的?如果题目不会做,如何通过步骤多得几分?一切尽在评分细则! 虽然高考命题组不会发布当年的评分细则,但各大学校的名师每 ...

  7. 2021高考本溪高中成绩查询,本溪市高级中学2020—2021学年度(上学期) 高一高二期中表奖大会...

    原标题:本溪市高级中学2020-2021学年度(上学期) 高一高二期中表奖大会 横空大气排山去,人间砥柱是此峰.在这个烟波致爽的时节,在这个书声琅琅的校园,璀璨的星辰却不仅高悬于九天之巅,也灵动在我们 ...

  8. 2021年跨境品牌集体出海,2020年跨境电商数据报告分享

    魔幻的2020年在跌宕起伏中落幕.2020年的旺季,大促节点模糊,卖家.服务商依旧拼尽全力冲刺,逆势增长.海外疫情反弹,多国再次封锁,集装箱短缺,海运价格持续高涨,物流难题贯穿2020年始终.另外,独 ...

  9. 2019海南大学计算机研究生分数线,2021海南大学研究生分数线一览表(含2019 2020历年复试分数线)...

    海南大学2021年研究生入学考试分数线是2022年研究生入学考试学生非常关心的问题,在选择研究生入学考试的院校和专业时,海南大学2021年研究生入学考试分数线就显得尤为重要.为方便您查询,小编整理了海 ...

最新文章

  1. 一文看懂国产最大深度学习平台上新,国内率先加持量子机器学习
  2. 编译与部署dubbo管控平台dubbo-admin
  3. string 类型详解
  4. 钉钉猛增40倍流量压力,阿里云DBA如何应对?
  5. Myeclipse启动Tomcat服务器Address already in use: JVM_Bind
  6. zabbix4监控mysql_Zabbix4监控Mysql5.7
  7. php怎么像git那样做diff,Git 基本操作
  8. Session赋值(备注)
  9. jQuery链式操作[转]
  10. Halcon 二维码
  11. cmake编译时不能指定头文件路径?
  12. 为什么说bagging是减少variance,而boosting是减少bias?
  13. python字符编码(一看就懂)
  14. Android 如何查看apk签名信息的MD5(SHA1和SHA256也可以)
  15. OEM造就整个IT产业
  16. USBKEY用户认证平台的研究和实现
  17. 360安全浏览器支持国密功能
  18. LMV324MTX单通道,双通道和四通道通用低电压轨至轨输出运算放大器TI
  19. 低代码真的是“行业毒瘤”?
  20. 数据分析师基本技能——SQL

热门文章

  1. java hashcode在线_java hashcode
  2. python注释几种类型
  3. Java: 函数式接口双冒号::实现方法引用,传递方法作为函数参数
  4. python集合中可以包含相同的元素_Python 集合可以包含相同的元素
  5. 清华计算几何大作业思路分析和代码实现
  6. Git恢复之前版本的两种方法reset、revert(图文详解)
  7. 2021-07-03 放 暑 假 啦
  8. 线下体验店或是VR落地的好选择,但是要避免用户的“一次性消费”
  9. 利用C#实现任务栏通知窗口
  10. html修改img图片颜色,通过css改变svg img的颜色