USACO 3.2 msquare 裸BFS】的更多相关文章

又是个裸BFS... 和西安网赛那道1006一样的,只不过加上了要记录方案.顺便复习map 记录方案直接在bfs队列的结点里加一个vector<int> opt,把从开头一直到当前结点的操作序列记下来 /* PROB:msquare LANG:C++ */ #include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue>…
Codeforce 1105 D. Kilani and the Game 解析(裸BFS.實作) 今天我們來看看CF1105D 題目連結 題目 給一個\(n\times m\)的地圖,地圖上有幾種格子:空地.路障.某個玩家的某些城堡.(可能有\(1\le p\le9\)個玩家) 給定一開始每個玩家至少有一個城堡,玩家照順序移動,每個玩家有自己的移動步數,求最後每個玩家能有幾個城堡. 前言 寫這題一直TLE,搞了好幾個小時才發現如果每次BFS都宣告一個新的queue,那麼可能會因為allocat…
1poj 3278 http://poj.org/problem?id=3278 #include<math.h> #include<algorithm> #include<string> #include<string.h> #include<stdio.h> #include<iostream> using namespace std; #define N 100005 #define M 155 #define INF 0x3f…
(1) USACO2.1 Ordered Fractions 枚举 排序即可,注意1/1 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ,L=1e5; struct fr{ int a,b; fr(,):a(q),b(w){} }f[L]; ; inline bool cmp(fr &x,fr &y)…
链接 本来想写spfa 加点什么限制什么的可能就过了 写着写着就成裸BFS了 也没优化就水过了 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<queue> using namespace std; #define N 110 #define M 10010 #define IN…
坑爹题,两种输入输出互相交换,裸bfs #include <stdio.h> #include <string.h> typedef struct { int x; int y; } point; point q[310]; int vis[15][15],mat[15][15]; int dx[4]= {1,0,-1,0}; int dy[4]= {0,1,0,-1}; char ans[5]= {"RTLB"}; int bfs1(int x,int y)…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题意:三维BFS,不解释 题解:DFS+剪枝会超时,裸BFS会超时,BFS+剪枝才能AC,有点伤,我以为数据会让DFS速度快一下,看来是我天真了 #include<cstdio> #include<queue> using namespace std; #define FFC(i,a,b) for(int i=a;i<=b;i++) ][][],a,b,c,ti,ok,ts…
OpenJudge 6044:鸣人和佐助 总时间限制: 1000ms  内存限制: 65536kB 描述 佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置.地图上的每个位置都可以走到,只不过有些位置上有大蛇丸的手下,需要先打败大蛇丸的手下才能到这些位置.鸣人有一定数量的查克拉,每一个单位的查克拉可以打败一个大蛇丸的手下.假设鸣人可以往上下左右四个方向移动,每移动一个距离需要花费1个单位时间,打败大蛇丸的手下不需要时间.如果鸣人查克拉消耗…
http://www.lydsy.com/JudgeOnline/problem.php?id=1627 裸bfs不解释.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using namespace std;…
题目描述 有一个n*m的棋盘(1<n,m<=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步 输入输出格式 输入格式: 一行四个数据,棋盘的大小和马的坐标 输出格式: 一个n*m的矩阵,代表马到达某个点最少要走几步(左对齐,宽5格,不能到达则输出-1) 输入输出样例 输入样例#1: 复制 3 3 1 1 输出样例#1: 复制 0 3 2 3 -1 1 2 1 4 思路:裸bfs,输出的时候比较坑是%-5d 代码: #include<cstdio> #in…