ZOJ 3865 Superbot(优先队列--模板)】的更多相关文章

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 主要思路:1.从一个点(cur)到它相邻的点(next),所需要的时间数(t)其实是固定的,而且这个移动过程后,到达next时,相应的方向也是固定的,找到求t的办法就好了.    2.到达一个未到达的点可能有多条路,优先队列取时间最短的路,则答案最优 题目: Superbot Superbot is an interesting game which you…
题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <queue> using namespace std; ; cons…
Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction left (1st position),…
不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4}; 我定义了一个方向数组,其实题目意思中的,指针移动还有操作版的变化本质上都是指针的移动 在此只需要 额外定义一个变量 cur 在数组 commandi 中循环移动即可 这道题目还是因为数据量不大吧,直接用 STL 中的 Queue 即可,优先队列肯定会更快. 总体来说,还是一道容易题. Sour…
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3865 思路 一个迷宫题 但是每次的操作数和普通的迷宫题不一样 0.按下按钮 即向当前方向盘的方向前进一格 1.往左移动方向盘 2.往右移动方向盘 3.不动 然后记录时间 易知,可以从四个方向到达终点,最后从这四个方向找最小值就是答案 当然要判断 不能通达的结果 AC代码 #include <cstdio> #include <cstring> #i…
按规则移动机器人 , 问是否能拾得宝藏 . 加了一个控制板 , 还增加了一个控制板移动周期 p 将移动周期变换一下 , 移动一次  就相当于光标向左不耗费时间的移动了一格 搜索思路 : 搜索当前格子到上下左右四个格子所花费的最短时间 . 记录光标的信息 , 和当前格子所需最短时间 . bfs + bfs #include <bits/stdc++.h> using namespace std; #define PI acos(-1.0) #define MAXN 20 #define INF…
优先队列模板 优先队列是用堆实现的,所以优先队列中的push().pop()操作的时间复杂度都是O(nlogn). 优先队列的初始化需要三个参数,元素类型.容器类型.比较算子. 需要熟悉的优先队列操作: q.top() 访问堆顶 q.push() 入堆 q.pop() 出堆 不同类型元素的优先级设置 定义堆需要注意最后两个> >之间有一个空格 数据结构 priority_queue < int, vector<int>, less<int> > q; //…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p/4420009.html 只不过状态用vis[20][20][4]来记录,每个点都有四个状态,访问过就不能访问 通过控制面板控制机器人找钻石,控制面板每p时间右移一次(队尾变队首),求最短路径 控制面板为左右上下的顺序,初始时 光标在左 有3种操作,占用一个单位时间 1. 光标左移(最左的移到最右…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24205    Accepted Submission(s): 8537 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
传送门: http://poj.org/problem?id=1511 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1008 题目大意: 给定p个点,还有他们的边q,(有向图)求从结点1出发到所有结点和所有结点到1的最短路径之和. 其中1 <= P,Q <= 1000000 思路: 和上次 POJ 3268 Silver Cow Party 一样,有向图倒着建立就把从所有结点到1的最短路径改为了从1到所有,那么只需两次d…
Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 217   Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is d…
上个礼拜学长讲了优先队列的说.... emmmmmm.... 看着题解敲了一题...先m下. #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #include<cstdio> #include<queue> using namespace std; struct gua { long long v,d; bool operator <…
#include<bits/stdc++.h> using namespace std; #define ll long long ; const ll inf=1e17; struct node { ll dis; int num,pos; node() {} node(ll dis,int num,int pos):dis(dis),num(num),pos(pos) {} bool operator< (const node& a)const { return dis>…
1. 优先队列 用途:按照某一个关键字对插入元素或删除元素后的数据集进行自动排序 复杂度: logN 2. 数据声明 (1)头文件:#include<queue> (2)声明:  priority_queue <T> q; //T是一个泛型,可以是结构体  priority_queue <T,vector<T>,greater<T> > q; greater函数也可以通过对结构体重载一个<运算符的bool函数 3. 库函数 q.size()…
Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you need to control the robot on an N*M grid map. As you see, it's just a simple game: there is a control panel with four direction left (1st position),…
传送门 洛谷 Solution 实测跑的比ST表快!!! 这个东西也是\(O(1)\)的,不会可以看我上一篇Blog 代码实现 代码戳这里…
Problem Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You…
/* 参考博文:http://www.cnblogs.com/ylfdrib/archive/2010/09/01/1814478.html 以下题解为转载代码自己写的: zoj2676 胡伯涛论文<最小割模型在信息学竞赛中的应用>中详细介绍了分数规划思想的应用.经典的有最优比率生成树. 对于分数规划的应用中,常用的就是0-1分数规划,即解向量X = {x1, --,xi, --}, 对于∀xi∈{0,1}. 主要求解过程是,首先将原分式优化问题,转换成非分式优化问题,利用单调的性质,用二分逼…
prim+优先队列模板: #include<stdio.h> //大概要这些头文件 #include<string.h> #include<queue> #include<vector> #include<algorithm> using namespace std; typedef pair<int,int> pii; ],next[],point[],val[],size,dist[]; //前向星及dist数组 ]; void…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 //hnldyhy(303882171) 11:12:46 // zoj 1649 //bfs +优先队列 #include <stdio.h> #include <iostream> #include <queue> using namespace std; struct node { int x; int y; int step; };…
C. Heap Operations time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Petya has recently learned data structure named "Binary heap". The heap he is now operating with allows the following…
优先队列也是一种先进先出的数据结构,元素从队尾入队,从队头出队,但是优先队列相较一般队列多了一个判断优先级的功能,在当前队列中,优先级最高的元素将被第一个删除. 先看一下优先队列的定义 template<class _Ty, class _Container = vector<_Ty>, class _Pr = less<typename _Container::value_type> > class priority_queue 第一个参数就是你要插入的类,比如int…
long long qpow(long long a,long long b,int mod) { ; while (b) { ) res=res*a%mod; a=a*a%mod; b>>=; } return res%mod; } 快速幂 ; ; ; bool show[mod3]; int hash(string a) { ; ,ha2=; int len=a.length(); ;i>-;i--) { ha1+=a[i]*val; ha1%=mod1; ha2+=a[i]*val…
做法:优先队列模板题,按步数从小到大为优先级,PASS掉曾经以相同氧气瓶走过的地方就好了 题目1 : Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en du…
前言 再过两天就\(NOIP2018\)了. 于是,我决定不做其他题目,开始一心一意刷板子了. 这篇博客记录的就是我的刷板子计划. [洛谷3383][模板]线性筛素数 这种普及-的题目我还写挂了两次(感觉自己废掉了). 好吧,第一次写挂是因为数组开小了,第二次写挂是因为没有特判\(1\)不是质数... ... class Class_LineSiever { private: #define PrimeSize 1000000 bool IsNot[PrimeSize+5]; public: i…
转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算法的预处理. 使用邻接矩阵的时间复杂度为O(n^2),用优先队列的复杂度为O((m+n)logn)近似为O(mlogn) (一) 过程 每次选择一个未访问过的到已经访问过(标记为Known)的所有点的集合的最短边,并用这个点进行更新,过程如下: Dv为最短路,而Pv为前面的顶点. 初始 在v1被标记…
新的整理版本版的地址见我新博客 http://www.hrwhisper.me/?p=1952 一.Dijkstra Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算法的预处理. 使用邻接矩阵的时间复杂度为O(n^2),用优先队列的复杂度为O((m+n)logn)近似为O(mlogn) (一)  过程 每次选择一个未访问过的到已经访问过(标记为Known)的所有点的集合的最短边,并用这个点进行更新,过程如下: Dv为最短路,而Pv为前面的顶点.…
昨天: 图论-概念与记录图的方法 以上是昨天的Blog,有需要者请先阅读完以上再阅读今天的Blog. 可能今天的有点乱,好好理理,认真看完相信你会懂得 分割线 第二天 引子:昨天我们简单讲了讲图的概念与记录图的方法,那么大家有一定的底子了,我们就开始初步接触图论算法了! 我们只讲Dijkstra和Floyd,因为其实在比赛中会这两个算法就很好了. 今天我们要讲的是:最短路径问题 Top1:最短路的概念 相信大家都知道有一款Made in China的导航软件--百度导航.那么他们是怎么为我们导航…
本篇博客已停更 本篇博客已停更 本篇博客已停更 吐槽区: 2020.04.15: 从今天起我做过的题目都记录一下,想不想写题解就另说了 2020.04.17: 写了两天之后真实的发现这是博主的摸鱼日记... 2020.04.22: 从清单中移除了 loj#6612,魔鬼树分块是不可能写的,这辈子都不可能写的 2020.04.22: 上了一下 bzoj 突然发现(通过抄代码和膜题解)过的题马上 500 道了,看了一下发现神 \(hjk\) 各大 OJ 过题量都是我的两倍,自闭了... 2020.0…
STL 简单记录.讲解一些初级阶段常用的用法. STL是C++的一个标准模板库,其中包含了许多在计算机领域常用的基本数据结构以及基本算法.STL主要依赖于模板,使得STL具有广泛的通用性.这篇文章旨在介绍一些常用的STL工具及其用法. Algorithm 该头文件涉及许多常用的功能,例如比较.交换.查找.遍历.绝对值.复制.修改.反转.排序等. 具体用法 /** 稍微列举部分可能用到的 **/ #include <iostream> #include <algorithm> #in…