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 ...
随机推荐
- Linux 搭建Discuz论坛
title: Linux 搭建Discuz论坛 Welcome to Fofade's Blog! 这里是Linux 搭建论坛的一些命令记录 命令摘记: 下载文件:Discuz 安装环境:PHP Ap ...
- 洛谷P3383 【模板】线性筛素数 (埃拉托斯特尼筛法)
题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行 ...
- [ USACO 2007 FEB ] Lilypad Pond (Gold)
\(\\\) \(Description\) 一张\(N\times M\)的网格,已知起点和终点,其中有一些地方是落脚点,有一些地方是空地,还有一些地方是坏点. 现在要从起点到终点,每次移动走日字\ ...
- arduino 字符解析
Arduino String.h库函数详解 此库中包含1 charAT()2 compareTo()3 concat()4 endsWith()5 equals()6 equalslgnoreCa ...
- [算法天天练] - C语言实现双向链表(一)
双向链表是比较常见的,主要是在链表的基础上添加prev指针,闲话少说直接上代码吧(这个也是网上一个大神的思路,真心不错,条理清楚,逻辑缜密) 主要也是为了学习,贴上我所调试成功的代码(Linux环境下 ...
- Spring+Spring MVC+Hibernate增查(使用注解)
使用Spring+Spring MVC+Hibernate做增删改查开发效率真的很高.使用Hibernate简化了JDBC连接数据库的的重复性代码.下面根据自己做的一个简单的增加和查询,把一些难点分析 ...
- Java基础(五)--内部类
内部类简单来说就是把一个类的定义放到另一个类的定义内部 内部类分为:成员内部类.局部内部类.匿名内部类.静态内部类 成员内部类:最常见的内部类 public class Outter { privat ...
- 04Servlet的生命周期
Servlet的生命周期 Servlet运行在Servlet容器中,其生命周期由容器来管理.Servlet的生命周期通过javax.servlet.Servlet接口中的init().service( ...
- 100 道 Linux 笔试题,能拿 80 分就算大神!
本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...
- datagrid总条数
1.getData var data=$("#dg").datagrid("getData");alert('总数据量:' + data.total)//注意你 ...