分析:一个n*m的矩阵,每个格子有12个状态,每次按一次,每个格子转90度,所以整个矩阵只有4种状态,然后爆搜就好了 #include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <stdlib.h> #include <cmath> #include <queue> using namespace std;…
最短路. $dis[i][j][k]$记录到点$(i,j)$,门的状态为$k$时的最短路.转移的时候有$8$种方案,即直接走向周围四个点,或者进行旋转.比较烦的是判断两个相邻的点在状态$k$下是否连通,仔细一些就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include&…
D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1…
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18847    Accepted Submission(s): 6090Special Judge Problem Description The Princess has been abducted by the BEelzebub…
http://codeforces.com/problemset/problem/540/C       Ice Cave Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 540C Description You play a computer game. Your character stands on some lev…
Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3159    Accepted Submission(s): 2106 Problem Description You're in space.You want to get home.There are asteroids.You don't want to hit…
题目 给定N个点和M条边,从点1出发,到达点T.寻找路径上边的个数小于等于K的路径,求出所有满足条件的路径中最长边长度的最小值. 题目链接:二分     最小化最大值,考虑采用二分搜索.对所有的边长进行排序,二分,对每次选择的边长,判断是否存在一条路径满足路径上所有的边长度均小于等于该边长,且路径中的边的个数小于等于K.     在判断路径是否存在的时候,使用BFS搜索,因为BFS用于寻找最短(边的个数最少)路径. 实现 #include<stdio.h> #include<string…
Ice Cave Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lowe…
参考博客:[算法入门]广度/宽度优先搜索(BFS) 适用问题:一个解/最优解 重点:我们怎么运用队列?怎么记录路径? 假设我们要找寻一条从V0到V6的最短路径.(明显看出这条最短路径就是V0->V2->V6) BFS搜索:首先看跟V0直接连接的节点V1.V2.V3,发现没有V6:进而再看跟V1.V2.V3直接连接的节点分别是:{V0, V4}.{V0, V1, V6}.{V0, V1, V5}(这里画删除线的意思是那些顶点在我们刚刚的搜索过程中已经找过了,我们不需要重新回头再看它们了):这时候…
Horse Pro bfs搜索,但图中存在负值坐标,两种方法解决. 用数组标记,将原点设为300,300 用map标记 http://oj.jxust.edu.cn/contest/Problem?id=1689&pid=5 #include <iostream> #include <cstdio> #include <queue> using namespace std; typedef long long ll; const int maxn = 10000…
题目分析: 本题是一题比较简单的bfs搜索题,首先由于数据给的比较多不能直接开二维数组存放,而是用了vector的动态的二维数组的形式存放,对于每个出发点,我们bfs向四周搜索,标记搜索过的点,遇到搜过的点就可以停止搜索了,每次搜一个点就和全局的最远距离比较,更远则代替,相同则比较此时编号的大小,如果编号更小则也可以代替 本题代码: 1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #incl…
题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终点坐标xm,ym,现在你可以选择在原地把地图上所有格子顺时针旋转90度:或者往上下左右走一格,问走到终点的最短路. 题解: 三维的bfs最短路,就是写起来比较麻烦. #include<iostream> #include<cstring> #include<cstdio>…
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最多只能向左走L个格子,向右R个格子,但是上下没有限制,现在给出出发点坐标(sx,sy),求能走的最大单元格数目. Examples Input Copy 4 53 21 2......***....***.... Output Copy 10 Input Copy 4 42 20 1......*.…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of b…
题意:给定一张N*M的地图,每一格都是一个房间,房间之间有门.每个房间可能有四个门,例如>代表右边只有一个门在右边即只能向右走,L代表左边没有门只能除了左其他都可以走等等.现在给出起点和终点,每次你可以把全部房间旋转90度或者移动到相邻的房间,但前提是两个房间之间都有有门,现在要你求起点出发到终点的最少时间. «+» means this block has 4 doors (one door to each neighbouring block); «-» means this block h…
题目: http://codeforces.com/problemset/problem/676/D code: #include <stdio.h> #define MAXN 1001 #define LEFT 0 #define TOP 1 #define RIGHT 2 #define BOTTOM 3 struct block{ //left,top,right,bottom ]; int doors_num; int rotats; int minutes; }; struct bl…
Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need a program to calculate the surface area of the walls inside the labyrinth. This job…
Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × k square, divided into unit squares. Please note that k ≥ 3 and is odd. We'll paint squares starting from the upper left square in the following orde…
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Description We all know that King Triton doesn't like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine…
Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 46715   Accepted: 14673 Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,00…
题目:http://codeforces.com/contest/398/problem/B 有点似曾相识的感觉,记忆中上次那个跟这个相似的 我是用了 暴力搜索过掉的,今天这个肯定不行了,dp方程想了非常久也没有想出来,有点无从下手的感觉,最后还是尝试了一下记忆化搜索,以dp[0][0]为边界,dp[x][y]代表当前有x行y列没有彩色的 瓷砖,搜索起来思路还是非常清晰的,可惜最后那个 算期望公式给写错了,瞎了好久,做出以后看了一下别人的做法,确实有点难想到,把涂好的都放在右下角,这样就仅仅有四…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game ju…
可以证明,如果我搜索的话,一个点最多只有两个最优状态:向左剩余步数最大时和向右剩余步数最大时 然后判一判,bfs就好了 dfs会T惨... #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll; +; inline ll rd(){ ll x=;; ;c=getchar();}…
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he…
题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# #.####.# #...#..# #S#E#### 9 5 ######### #.#.#.#.# S.......E #.#.#.#.# ######### Sample Output 37 5 5 17 17 9题目分析:T组数据,每组都会有一个起点S,一个终点E. 分别输出:左边优先搜索到E…
题目: 链接 思路: 用BFS分别以‘Y’和‘M’的位置为起点进行两次搜索,并把这两次的搜索结果在一个二维数组中保存下来,在对地图遍历遇到‘@’更行最小值. PS: 如果用‘Y’和‘M’点分别去搜每个‘@’,这样妥妥的会超时.当时做这个题脑抽的一批……(烦!!!) 另外如果‘Y’和‘M’到不了‘@’这里的值为0,应该把这种情况排除. 代码: //#include <bits/stdc++.h> #include <queue> #include <cstdio> #in…
http://codeforces.com/gym/101246/problem/J 题意:给出n个点坐标,要使这些点间距相同的话,就要移动这些点,问最少的需要的移动距离是多少,并输出移动后的坐标. 思路:昨晚比赛确定的一点就是通过X分搜索去枚举间距,使得最后的移动距离最短. 不过使用的是二分,而且写的时候也只枚举了起点和终点,后面想了要枚举所有的点,但时间来不及. 因为间距的单调不会使得答案单调,间距过大过小都会使得最后的移动距离不是最优,所以是使用三分而不是二分,顺便重温一下三分. whil…
HDU 1043八数码问题 八数码,就是1~8加上一个空格的九宫格,这道题以及这个游戏的目标就是把九宫格还原到从左到右从上到下是1~8然后最后是空格. 没了解康托展开之前,这道题怎么想都觉得很棘手,直接搜索的话也不知道怎么剪枝,而且判重也不可能开一个9维的数组,空间也不允许,所以先了解康托展开是无可厚非的第一步,这里就引用一下大佬的介绍,很简单很实用的关于全排列的一个东西 康托展开和逆康托展开 学会康托展开之后这道题就有很多解法了,很多是用A*的,不过这个我还没学会,只能弱弱的用万能的搜索来暴力…
链接: https://codeforces.com/contest/1283/problem/D 题意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小. 思路:贪心一下,首先每个点的x+1和x-1两个坐标到这个点的距离是最短的,之后是x+2,x-2,再之后是x+3,x-3,那么可以想到bfs,首先把n个点存入队列中,找与他们距离为1的点,之后再bfs距离为2的点,如此这个过程直到找到m个点. AC代码: #include<iostream> #incl…
给出烟花的爆炸方式和爆炸次数 问最后有多少个格子会被炸到 如果dfs的话会超时... 利用模拟每一层来搜索..? 思想就是一开始有一个爆炸点向上 然后模拟完第一段 会产生一个爆炸点 朝两个方向 就用vector来存 每一层都处理一段的爆炸点 产生新一段的爆炸点 因为5*30=150 所以图建300就可以了 300 * 300 * 30的时间复杂度 但是常数很大..不过无所谓啦.. 需要注意的是 一个爆炸点可能会同时出现两次朝同一个方向开始爆炸的烟花 这个是没有意义的 所以拿一个数组来记录 不然最…