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 ...
随机推荐
- mysql left join 出现的结果会重复
left join 基本用法 MySQL left join 语句格式 A LEFT JOIN B ON 条件表达式 left join 是以A表为基础,A表即左表,B表即右表. 左表(A)的记录会全 ...
- 【js】再谈移动端的模态框实现
移动端模态框的机制因为与PC的模态框机制一直有所区别,一直是许多新人很容易踩坑的地方,最近笔者作为一条老咸鱼也踩进了一个新坑中,真是平日里代码读得太粗略,故而写上几笔,以儆效尤. 故事的起因是这样的, ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- JDK API文档下载
java SE 8 API文档:http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-21331 ...
- Github 文件选择性上传
用过Github的人都知道.gitignore文件的存在,但是实际用起来还是有一些需要注意的地方,尤其是对于新手来说,稍不注意就会出错. 一.Github选择性忽略特定文件的方式 1.全局设置 一 ...
- Linux软件管理和安装
软件安装和管理软件包1.bin文件.bin2.rpm包3.源码压缩包 安装软件的步骤: 1.检查是否已经安装 rpm -qa | grep jdk 2.下载软件包 3.安装 依赖 rpm 包,已经编译 ...
- jQuery实现将div中滚动条滚动到指定位置的方法
1.JS代码: onload = function () { //初始化 scrollToLocation(); }; function scrollToLocation() { var mainCo ...
- 从React看weight开发
从当前云发展的势头来看几乎所有互联网应用都趋向大一统的趋势,一个node下面加一堆应用,同时我们项目也趋向把复杂的大应用拆分成多个小应用,通过各种复杂的Api来协作,通信,达到同样的效果. 可以看出, ...
- eclipse中添加maven
收藏一下,一篇很好的例子 maven相关插件:链接:http://pan.baidu.com/s/1i3Ks95j 密码:7pgh eclipse:链接:http://pan.baidu.com/s/ ...
- C_动态库|静态库
动态库 动态链接库简称DLL,同时以.dll 为后缀,主要用于提供代码和数据 dll 并不是所有数据都能被访问到,必须要进行导出 动态链接库在内存中始终只保存了一份数据,起到了节约内存的作用 生成动态 ...