传送门

分析

首先我们要知道为了情况最坏,无论你到哪,一定会在你前往绿洲的最短路上的那片沙子上刮风,所以这个点到绿洲的最短路即为他相连的点中到绿洲距离最短的距离+3和次短的距离+1的最小值,具体实现见代码。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl;
const int inf=0x3f3f3f3f;
const int dx[]={-,,,-,,-,,},dy[]={-,-,-,,,,,};
class DesertWind {
public:
int a[][],ans[][],n,m;
bool is(int x,int y){
if(x<||y<||x>n||y>m||a[x][y]==inf)return false;
return true;
}
int daysNeeded(vector<string>theMap){
n=theMap.size(),m=theMap[].length();
int i,j,sx,sy,k;
memset(ans,0x3f,sizeof(ans));
memset(a,0x3f,sizeof(a));
for(i=;i<n;i++)
for(j=;j<m;j++)
if(theMap[i][j]=='@')sx=i+,sy=j+,a[i+][j+]=;
else if(theMap[i][j]=='-')a[i+][j+]=;
else if(theMap[i][j]=='*'){
a[i+][j+]=;
ans[i+][j+]=;
}
for(int _=;_<=n*m;_++)
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(a[i][j]!=inf){
int cnt=,d[];
for(k=;k<=;k++)d[k]=inf;
for(k=;k<;k++){
int x=i+dx[k],y=j+dy[k];
if(is(x,y))d[++cnt]=ans[x][y];
}
sort(d+,d+cnt+);
ans[i][j]=min(ans[i][j],min(d[]+,d[]+));
}
return ans[sx][sy]==inf?-:ans[sx][sy];
}
};

DesertWind TopCoder - 1570的更多相关文章

  1. TopCoder kawigiEdit插件配置

    kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...

  2. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  3. TopCoder比赛总结表

    TopCoder                        250                              500                                 ...

  4. Topcoder几例C++字符串应用

    本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...

  5. TopCoder

    在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...

  6. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  7. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  8. TopCoder SRM 590

     第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement     Fox Ciel is going to play Gomoku with her friend ...

  9. Topcoder Arena插件配置和训练指南

    一. Arena插件配置 1. 下载Arena 指针:http://community.topcoder.com/tc?module=MyHome 左边Competitions->Algorit ...

随机推荐

  1. shell_script_查询主机名、ip地址 、DNS地址

    #!/bin/bashhostnameip=`/sbin/ifconfig eth0|grep "inet addr:"|sed 's/Bcast.*$//'g |awk -F & ...

  2. Microsoft Visual Studio Ultimate 2013 RC 离线安装程序

    Microsoft Visual Studio Ultimate 2013 RC 离线安装程序 ☆ 微软官网地址:☆ http://www.microsoft.com/en-us/download/d ...

  3. np.unique 的实现

    1. 简单实现 import numpy as np def unique(ar): perm = ar.argsort() aux = ar[perm] flag = np.concatenate( ...

  4. The Great Mixing

    Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th typ ...

  5. Node.Js and Mongoose

    Mongoose官方API,我做完之后整理出来的心得. ONE· Getting Started First be sure you have MongoDB and Node.js installe ...

  6. 畅通工程再续 (kruskal算法的延续)

    个人心得:这题其实跟上一题没什么区别,自己想办法把坐标啥的都给转换为对应的图形模样就好了 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实 ...

  7. 关于jsp和html页面中的三种弹出框

    代码: <!-- 引入jquery 由于在下面使用jquery选择器,与弹出框无关 --> <script type="text/javascript" src= ...

  8. svn更新报错:出现skipped:目标路径

    skipped 意为:跳过此目标文件: 一般出现在目标文件被删除后,重新更新情况下: 解决办法及结果: 1,回到此目标文件的上一层文件夹,team-clean up,结果不成功 2,回到此目标文件的上 ...

  9. MongoDB优化之一:常见优化方法

    常用性能优化方案 创建索引 限定返回结果数 只查询使用到的字段 采用capped collection 采用Server Side Code Execution 使用Hint,强制使用索引 Hint ...

  10. webscheduler 开源定时服务和延迟服务

    源码地址:https://gitee.com/eabeat/webscheduler 架构上采用 asp.net + access ,实现简单的管理界面,可以维护调用API,查看日志等功能.内核采用Q ...