D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: standard input output :standard output The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is loca…
http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移动一格.隧道里有车,每次人移动以后,车会向右移动两格,人与车轮流运动. 题解,将每次车的移动变成人往右移动两格,然后就能搜索了.dfs,用vis数组判掉已经移动到的格子(因为已经移动到的格子要么是不能走到底的,要么就可以走完).注意他只能移动到三的倍数的格子,所以读入map后要再后面加两列'.' #def…
题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格,然后人再向右移动两格. 然后就可以进行状态转移了. f[i][j]表示能否走到i行j列的位置.最后在终点处查找是否存在f[i][ed]为1即可. #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i(a…
这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人向上或向下或不动一步 + 向右三步 这样就变为走迷宫问题了 同样要注意 1.去重数组 或者 将以前访问过的点置为其他符号 避免重复访问 2.还有 因为 每次是三步三步的往右走 所以最后的边界可能不够 可以再扩充三列 #include <iostream> #include <stdio.h&…
D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/D Description The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one en…
/* CF586D. Phillip and Trains http://codeforces.com/problemset/problem/586/D 搜索 */ #include<cstdio> #include<algorithm> #include<string.h> using namespace std; ; ][Nmax]; ][Nmax]; int n,k; int t,ans; int dfs(int step,int pos) { &&…
Distinct Paths 题目链接:http://codeforces.com/problemset/problem/293/B 数据范围:略. 题解: 带搜索的剪枝.... 想不到吧..... 但是剪枝也比较简单,就是能想到的剪枝都加上能过的那种搜索题. 代码: #include <bits/stdc++.h> #define setIO(s) freopen(s".in", "r", stdin), freopen(s".out&quo…
Description In mathematics, the four color theorem, or the four color map theorem, states that, given any separation of a plane into contiguous regions, producing a figure called a map, no more than four colors are required to color the regions of th…
题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple game called "Rake It In". Two players, Alice and Bob, initially select an integer k and initialize a score indicator. An \(4 \times 4\) board is…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel a…
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. 题解: 就首先预处理一下每个点在哪些时刻会被车子占领,然后从右向左dp一下就好 代码: #include<iostream> #include<cstring> #include<string> #include<vector> #include<alg…
题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会从右边继续进来, 一开始是人先往右走一步,然后上下或者一步,然后火车往左移两步. n有100,代表长度,k代表火车的数量: 思路: BFS; 走完还要再走两个= =.妈个鸡啊. 一开始一直踏马地觉得没必要BFS,没必要BFS...后面搞懂了之前比赛中的思路是递推,也就是DP,但是踏马的DP递推真的写…
LINK:智破连环阵 考试的时候 题意没理解清楚 题目是指一个炸弹爆炸时间结束后再放另一个炸弹 而放完一个炸弹紧接另一个炸弹.题目中存在然后二字. 这样我们可以发现某个炸弹只会炸连续的一段. 但是 由于点的坐标虽然只在第一象限 炸弹也在第一象限 不过简单的设出几个状态可以发现 是不可行的. 状压也不行.考虑贪心但是还是要要考虑坐标以及序号的问题 所以很难贪出正确答案. 无奈之下只能选择搜索了 一种比较简单的搜索方式还是搜出把序列分段. 可以发现这样复杂度最坏是2^n的. 求出分段之后我们还需要考…
题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep>t剪枝 ②搜到一个解后剪枝 ③当前走到终点最少步数>满足条件还需要走的步数剪枝(关键) ③奇偶剪枝(关键):当前走到终点步数的奇偶性应该与满足条件还需要走的步数奇偶性一致. 其中三四两步放在一步中写:remain=abs(x-ex)+abs(y-ey)-abs(dep-t) 奇偶剪枝的原理:abs(…
500ms时限406ms水过…… 直接枚举肯定超时,需要剪枝. 枚举每个格子的元素,检查其左上角和正上方格子是否满足条件,若不满足不必再向下搜索. 在 这里 看到一个更好的方法: 枚举每个格子是哪个相邻的比它大.然后DFS看看有没有环.这样的复杂度只有(2^5*3^5). 不过我没写出来……而且也不太清楚这个时间复杂度是怎么算的……求指点! #include <cstdio> #include <cstring> #include <cstdlib> , , , };…
题目链接 题意:给出几个基因片段,要求你将它们排列成一个最短的序列,序列中使用了所有的基因片段,而且不能翻转基因. 分析:先计算出add数组,再dfs枚举. 空间复杂度O(n*n),  最坏时间复杂度 O(n^n),但是剪枝以后很快,因为好多搜不到后面,搜不到第n层. #include <iostream> #include <cstring> #include <cstdlib> #include <cmath> #include <cstdio&g…
这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我发现了许多搜索上的问题.思路非常简 单:搜索出每一种可能的配对方式,然后从每一个点出发 一遍,模拟走的过程,如果到死循环里面就答案加一,那个模拟走的过程话说我敲的还是很爽的,这题难在对配对序列的搜索和配对状态重 复的剪枝上面. 记得配对序列的搜索我敲了5.6个版本,发现AC之后一个都没有用上,但是在…
题目链接 遍历每个点, 如果这个点的值能被k整除并且k/a[i][j]后小于等于n*m, 那么就对这个点进行搜索. 将这个点加入队列, 将周围的所有大于等于这个点的值的点也加入队列. 不断重复, 直到队列空或者数量满足要求. 可以加一个额外的数组, 如果搜索的过程中, 这个值和a[i][j]相同, 那么就把这个格子标记, 减少额外的操作. #include <iostream> #include <vector> #include <cstdio> #include &…
The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n co…
C. Connect time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alice lives on a flat planet that can be modeled as a square grid of size n×nn×n , with rows and columns enumerated from 11 to nn…
题目背景 数据有更改 题目描述 某乡有nn个村庄(1<n \le 201<n≤20),有一个售货员,他要到各个村庄去售货,各村庄之间的路程s(0<s<1000)s(0<s<1000)是已知的,且AA村到BB村与BB村到AA村的路大多不同.为了提高效率,他从商店出发到每个村庄一次,然后返回商店所在的村,假设商店所在的村庄为11,他不知道选择什么样的路线才能使所走的路程最短.请你帮他选择一条最短的路. 输入输出格式 输入格式: 村庄数nn和各村之间的路程(均是整数). 输出…
1. Palindrome Partitioning https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab&…
Find the Winning Move Time Limit: 3000MS   Memory Limit: 32768K Total Submissions: 1286   Accepted: 626 Description 4x4 tic-tac-toe is played on a board with four rows (numbered 0 to 3 from top to bottom) and four columns (numbered 0 to 3 from left t…
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 1 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. Howe…
极小极大搜索 的个人理解(alpha-beta剪枝) 主要算法依据就是根据极大极小搜索实现的. 苦逼的是,查了两个晚上的错,原来最终是判断函数写错了..瞬间吐血! ps. 据说加一句 if sum < 4 printf("#####\n")会变态的快,不过懒得加了 ps. 1表示胜利,0表示平局,-1表示失败. #include <cstdio> #include <cstring> #include <iostream> #include &…
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: . Input The first line contains…
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-andrew-stankevich-contest-37-asc-37-en.pdf 题意 给你一个n,问你有多少a和x满足:x在a中二分会返回true,其中a的长度是n 题解 考虑到二分的过程不是向左就是向右,所以可以暴力搜索搞到若干序列,这些序列都是由向左或者向右组成的.枚举x,设向左的有i个,向右…
Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca suddenly realize that every integer can be represented by digit '1', plus operator and minus operator. For example, 1534 can be represented as 1111 +…
写了一下午,终于AC了. 由于n<=5, 所以不需要太多的剪枝和技巧也能过.可以将操作后的消方块和下落和剪枝函数写到一个结构体中,这样会减少调试难度,更加简洁. 可以采用如下剪枝: 1. 如果当前有一种颜色少于两个,则一定无解. 2. 如果相邻颜色相同则不交换. 3. 优先考虑右移 4. 其实可以开一个unordered_map来避免重复搜索,由于笔者已经筋疲力尽,就没有进行这部优化(但其实n的规模太小,不开也无所谓). 代码: #include<cstdio> #include<…
hdu有毒,考试上 AC 的就是一直 WA- 其实这道题是可以进行初始化来进行优化的,这样的话询问次数是可以达到 10510^5105 的.不过普通的 dfsdfsdfs + 剪枝也是可过的. Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 1000 + 2; int G[maxn][maxn], n, m, q, a,…