tyvj1117 拯救ice-cream
背景
可是……停电了……
冰淇淋们躺在Ice-cream home的冰柜里,慢慢地……慢慢地……融化…………
你说,她能赶在冰淇淋融化完之前赶到Ice-cream home去吗?
描述
输入格式
输出格式
测试样例1
输入
11
10
8
......s...
..........
#ooooooo.o
#.........
#.........
#.........
#.....m...
#.........
输出
10
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct node{
int x;
int y;
int dist;
friend bool operator < (node a,node b){
return a.dist > b.dist;
}
};
priority_queue<node> q;
int t,x,y,startx,starty,endx,endy,map[][],jud[][];
int dx[] = {-,,,};
int dy[] = {,-,,};
void input(){
cin>>t>>x>>y;
char cmd;
for(int i = ;i <= y;i++){
for(int j = ;j <= x;j++){
cin>>cmd;
if(cmd == '.') map[i][j] = ;
if(cmd == '#') map[i][j] = ;
if(cmd == 'o') map[i][j] = ;
if(cmd == 's'){
map[i][j] = ;
startx = j;
starty = i;
}
if(cmd == 'm'){
map[i][j] = ;
endx = j;
endy = i;
}
}
}
node tmp;
tmp.x = startx;
tmp.y = starty;
tmp.dist = ;
q.push(tmp);
for(int i = ;i <= ;i++){
for(int j = ;j <= ;j++){
jud[i][j] = ;
}
}
}
bool bfs(){
node now,next;
int nx,ny;
while(!q.empty()){
now = q.top();
q.pop();
for(int i = ;i < ;i++){
nx = now.x + dx[i];
ny = now.y + dy[i];
if(nx < || nx > x || ny < || ny > y || map[ny][nx] == ||jud[ny][nx] <= now.dist + map[ny][nx]) continue;
next.x = nx;
next.y = ny;
next.dist = now.dist + map[ny][nx];
if(nx == endx && ny == endy){
if(next.dist >= t) return false;
else{
cout<<next.dist<<endl;
return true;
}
}
q.push(next);
jud[ny][nx] = next.dist;
}
}
}
int main(){
input();
if(!bfs()) cout<<<<endl;
return ;
}
tyvj1117 拯救ice-cream的更多相关文章
- HackerRank Ice Cream Parlor
传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...
- How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich
ShareThis - By Vikas Verma Bluetooth low energy (BLE) is a feature of Bluetooth 4.0 wireless radio t ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Ice Cream Tower
2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...
- 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心
/** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...
- E. Sonya and Ice Cream(开拓思维)
E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【HackerRank】Ice Cream Parlor
Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N ...
- 【Codeforces Round #411 (Div. 1)】Codeforces 804C Ice cream coloring (DFS)
传送门 分析 这道题做了好长时间,题意就很难理解. 我们注意到这句话Vertices which have the i-th (1 ≤ i ≤ m) type of ice cream form a ...
- 【dfs+理解题意+构造】【待重做】codeforces E. Ice cream coloring
http://codeforces.com/contest/805/problem/E [题意] 染色数是很好确定,最少染色数是max(si)(最小为1,即使所有的si都为0,这样是单节点树形成的森林 ...
- codeforces 686A A. Free Ice Cream(水题)
题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...
随机推荐
- python中socket编程
一.网络协议 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构(互联网中处处是C/S架构):B/S架构也是C/S架构的一种,B/S是浏览器/服务器 C/S架构与socket的关系: ...
- redis在linux安装和开机启动和结合php运用方法一
第一部分:安装redis 希望将redis安装到此目录 1 /usr/local/redis 希望将安装包下载到此目录 1 /usr/local/src 那么安装过程指令如下: 1 2 3 4 5 6 ...
- vue中sync,v-model----双向数据绑定
需求:父子组件同步数据 实现方式:sync或者v-model 一.sync 官网:https://cn.vuejs.org/v2/guide/components-custom-events.html ...
- 关于Android皮肤更换分享
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=264902&highlight=%E6%8D%A2%E8%82%A4&a ...
- c语言小项目-使用mysql数据库的图书管理系统
VS2013通过MySQL方式连接到MySQL MySQL官网上C++的API有两个.一个是很成熟的mysql++,另一个是MySQL Connector/C++,近两年才出的,模仿JDBC做的,封装 ...
- Hibernate 一对多查询对set的排序
Hibernate可以进行一对多的关联查询,例如:查询了试卷题目,可以自动获取试卷题目的选项对象. 但是关联出来的集合对象是无序的,那么在显示的时候就会有问题,经过百度发现可以对Set进行设置排序. ...
- 391 Perfect Rectangle 完美矩形
有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域.每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2]. ( ...
- bnu 51640 Training Plan DP
https://www.bnuoj.com/bnuoj/problem_show.php?pid=51640 dp[i][j]表示前j个数,分成了i组,最小需要多少精力. 那么,求解订票dp[i][j ...
- C# 代码笔记_文件
string Route = @"D:\ksy\ksy\WebSite1\";//文件地址 string File_name = "user ...
- 专题三:自定义Web服务器
前言: 经过前面的专题中对网络层协议和HTTP协议的简单介绍相信大家对网络中的协议有了大致的了解的, 本专题将针对HTTP协议定义一个Web服务器,我们平常浏览网页通过在浏览器中输入一个网址就可以看到 ...