背景

天好热……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. python中socket编程

    一.网络协议 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构(互联网中处处是C/S架构):B/S架构也是C/S架构的一种,B/S是浏览器/服务器 C/S架构与socket的关系: ...

  2. redis在linux安装和开机启动和结合php运用方法一

    第一部分:安装redis 希望将redis安装到此目录 1 /usr/local/redis 希望将安装包下载到此目录 1 /usr/local/src 那么安装过程指令如下: 1 2 3 4 5 6 ...

  3. vue中sync,v-model----双向数据绑定

    需求:父子组件同步数据 实现方式:sync或者v-model 一.sync 官网:https://cn.vuejs.org/v2/guide/components-custom-events.html ...

  4. 关于Android皮肤更换分享

    http://www.eoeandroid.com/forum.php?mod=viewthread&tid=264902&highlight=%E6%8D%A2%E8%82%A4&a ...

  5. c语言小项目-使用mysql数据库的图书管理系统

    VS2013通过MySQL方式连接到MySQL MySQL官网上C++的API有两个.一个是很成熟的mysql++,另一个是MySQL Connector/C++,近两年才出的,模仿JDBC做的,封装 ...

  6. Hibernate 一对多查询对set的排序

    Hibernate可以进行一对多的关联查询,例如:查询了试卷题目,可以自动获取试卷题目的选项对象. 但是关联出来的集合对象是无序的,那么在显示的时候就会有问题,经过百度发现可以对Set进行设置排序. ...

  7. 391 Perfect Rectangle 完美矩形

    有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域.每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2]. ( ...

  8. bnu 51640 Training Plan DP

    https://www.bnuoj.com/bnuoj/problem_show.php?pid=51640 dp[i][j]表示前j个数,分成了i组,最小需要多少精力. 那么,求解订票dp[i][j ...

  9. C# 代码笔记_文件

           string Route = @"D:\ksy\ksy\WebSite1\";//文件地址         string File_name = "user ...

  10. 专题三:自定义Web服务器

    前言: 经过前面的专题中对网络层协议和HTTP协议的简单介绍相信大家对网络中的协议有了大致的了解的, 本专题将针对HTTP协议定义一个Web服务器,我们平常浏览网页通过在浏览器中输入一个网址就可以看到 ...