背景

天好热……Tina顶着那炎炎的烈日,向Ice-cream home走去……
可是……停电了……
冰淇淋们躺在Ice-cream home的冰柜里,慢慢地……慢慢地……融化…………
你说,她能赶在冰淇淋融化完之前赶到Ice-cream home去吗?

描述

给你一张坐标图,s为Tina的初始位置,m为Ice-cream home的位置,‘.’为路面,Tina在上面,每单位时间可以移动一格;‘#’为草地,Tina在上面,每两单位时间可以移动一格(建议不要模仿—毕竟Tina还小);‘o’是障碍物,Tina不能在它上面行动。也就是说,Tina只能在路面或草地上行走,必须绕过障碍物,并到达冰淇淋店。但是…………不保证到达时,冰淇淋还未融化,所以……就请聪明的你……选择最佳的方案啦…………如果,Tina到的时候,冰淇淋已经融化完了,那她可是会哭的。

输入格式

依次输入冰淇淋的融化时间t(0<t<1000),坐标图的长x,宽y(5<=x,y<=25){太长打起来好累……},和整张坐标图。

输出格式

判断按照最优方案是否可以赶在冰淇淋融化之前到达冰淇淋店(注:当T=最优方案所用时间,则判断为未赶到),如赶到,输出所用时间;如未赶到,输出Tina的哭声——“55555”(不包括引号)。

测试样例1

输入

11 
10 

......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的更多相关文章

  1. HackerRank Ice Cream Parlor

    传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...

  2. 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 ...

  3. 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 ...

  4. Ice Cream Tower

    2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...

  5. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

  6. E. Sonya and Ice Cream(开拓思维)

    E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. 【HackerRank】Ice Cream Parlor

    Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N ...

  8. 【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 ...

  9. 【dfs+理解题意+构造】【待重做】codeforces E. Ice cream coloring

    http://codeforces.com/contest/805/problem/E [题意] 染色数是很好确定,最少染色数是max(si)(最小为1,即使所有的si都为0,这样是单节点树形成的森林 ...

  10. codeforces 686A A. Free Ice Cream(水题)

    题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...

随机推荐

  1. Linux 搭建Discuz论坛

    title: Linux 搭建Discuz论坛 Welcome to Fofade's Blog! 这里是Linux 搭建论坛的一些命令记录 命令摘记: 下载文件:Discuz 安装环境:PHP Ap ...

  2. 洛谷P3383 【模板】线性筛素数 (埃拉托斯特尼筛法)

    题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行 ...

  3. [ USACO 2007 FEB ] Lilypad Pond (Gold)

    \(\\\) \(Description\) 一张\(N\times M\)的网格,已知起点和终点,其中有一些地方是落脚点,有一些地方是空地,还有一些地方是坏点. 现在要从起点到终点,每次移动走日字\ ...

  4. arduino 字符解析

    Arduino String.h库函数详解   此库中包含1 charAT()2 compareTo()3 concat()4 endsWith()5 equals()6 equalslgnoreCa ...

  5. [算法天天练] - C语言实现双向链表(一)

    双向链表是比较常见的,主要是在链表的基础上添加prev指针,闲话少说直接上代码吧(这个也是网上一个大神的思路,真心不错,条理清楚,逻辑缜密) 主要也是为了学习,贴上我所调试成功的代码(Linux环境下 ...

  6. Spring+Spring MVC+Hibernate增查(使用注解)

    使用Spring+Spring MVC+Hibernate做增删改查开发效率真的很高.使用Hibernate简化了JDBC连接数据库的的重复性代码.下面根据自己做的一个简单的增加和查询,把一些难点分析 ...

  7. Java基础(五)--内部类

    内部类简单来说就是把一个类的定义放到另一个类的定义内部 内部类分为:成员内部类.局部内部类.匿名内部类.静态内部类 成员内部类:最常见的内部类 public class Outter { privat ...

  8. 04Servlet的生命周期

    Servlet的生命周期 Servlet运行在Servlet容器中,其生命周期由容器来管理.Servlet的生命周期通过javax.servlet.Servlet接口中的init().service( ...

  9. 100 道 Linux 笔试题,能拿 80 分就算大神!

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...

  10. datagrid总条数

    1.getData var data=$("#dg").datagrid("getData");alert('总数据量:' + data.total)//注意你 ...