读懂题意以后还很容易做的, 和AbbottsRevenge类似加一个维度,筛子的形态,可以用上方的点数u和前面的点数f来表示,相对的面点数之和为7,可以预先存储u和f的对应右边的点数,点数转化就很容易了. 具体做法看代码 #include<bits/stdc++.h> using namespace std; ; ; int g[maxn][maxn]; bool vis[maxn][maxn][maxd][maxd]; struct State { int x,y,u,f,pre; }Q[]…
UVA 810 - A Dicey Problem 题目链接 题意:一个骰子,给你顶面和前面.在一个起点,每次能移动到周围4格,为-1,或顶面和该位置数字一样,那么问题来了,骰子能不能走一圈回到原地,输出路径,要求最短,假设有多个最短,依照上下左右输出 思路:读懂题就是水题,就记忆化搜一下就可以,记录状态为位置和骰子顶面.正面(由于有两面就能确定骰子了) 代码: #include <cstdio> #include <cstring> #include <vector>…
根据状态进行bfs,手动打表维护骰子滚动. AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include…
Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money." Hagrid: "Well there's your money, Harry! Gringotts, the wizard bank! Ain't no safer place. Not one. Except perhaps Hogwarts." ― Rubeus Hagrid…
Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3847    Accepted Submission(s): 1661 Problem Description Now an emergent task for you is to open a password lock. The password is co…
题目描述:https://uva.onlinejudge.org/external/8/810.pdf 把一个骰子放在一个M x N的地图上,让他按照规定滚动,求滚回原点的最短路径. 思路:  记忆化搜索(我这里用的dfs深度优先搜索) 难点: 如何推导骰子的状态 我没有用打表,而是先用build_dice()初始化二维数组dice, 这样,当我们有骰子的顶面top,正面face, 就可以通过dice[top][face] 获得对应的右面,由此,就可以实现骰子的旋转.rotate()函数实现骰子…
1784: Camellia的难题 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 67  Solved: 14SubmitStatusWeb Board Description Camellia遇到了一个问题,她无法解决所以来求助豆子,以下是豆子所理解的问题:给定1000万个点,编号1-1000万.每个点都有一个值,初始的时候均为-1,有n个操作,操作有以下五种. 1 x 代表将x点更新为i,i为第几次操作. 2 x 代表将x点更新为-1. 3…
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #inclu…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题意 输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数.直到输入0 0时程序结束 分析: 如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6. 下面给出AC代码: #include <bits/stdc++.h&…
  How Big Is It?  Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom of the b…
题意:给定4个数,a,b,c,d,分别代表空杯子容积为a,b,一个盛满水的杯子容积为c,让你不断倒水,找一个dd,是不是存在某个时刻, 某个杯子里的水dd,和d相同,或者无限接近.让求最少的倒水量和dd(可能和d相同). 析:首先由于没有刻度,如果用数学方法计算,不好算,样例还好算一点,我们观察那个a,b,c都不大于200,挺小的,适合暴力求解. 就是把所有情况都倒一次,倒水就两种倒法,要么把一个杯子倒满,要么就是这个杯子空了,由于水量是固定的,那么确定两个杯子的水量, 那么第三个也就确定了,所…
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给出AC代码: #include <bits/stdc++.h> using namespace std; int k,m; int main() { while(~scanf("%d%d"…
题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. If you cannot find a positive sequen…
题面 著名的TSP问题,NPC问题 对于数据大的情况,我们可以使用一系列近似算法进行寻找解. 对于数据规模小的情况,我们可以直接暴力dp 一开始写了一个dfs,然后就被n=20的数据卡爆了 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using std::min; const int maxn=22; int f[1<<maxn][maxn];…
You live in a small town with R bidirectional roads connecting C crossings and you want to go from crossing 1 to crossing C as soon as possible. You can visit other crossings before arriving at crossing C, but it's not mandatory. You have exactly one…
题意就是给一张无向图,去掉某些结点,然后连成一条链,问最少去掉几个结点. n很小n<=15,所以直接枚举2^15个状态就行啦. 链的条件是1.无环,2.没有度大于2的点,3.把n个散链连起来需要n-1次拼接,去掉的结点数>=n-1. #include<bits/stdc++.h> using namespace std; ; int G[maxn][maxn]; int n; int c[maxn]; bool dfs(int u,int s,int fa) { c[u] = ;…
题意:给定一个数 n,求它后一个素数和前一个素数差. 析:先打表,再二分查找. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring&…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5661 题意: 给你一个长度为n的整数序列,询问任意区间的极端异或和. 定义极端异或和: 当长度n > 1 的时候,将数组长度缩小到n-1. [a1, a2, a3 ···, an] -> [a1⊕a2,  a2⊕a3, a3⊕a4, ···, an-1⊕…
题意:给两个6行5列的字母矩阵,找出满足如下条件的“密码”:密码中的每个字母在两个矩阵的对应列中均出现.给定k(1<=k<=7777),你的任务是找出字典序第k小的密码.如果不存在,输出NO. 分析:因为k<=7777,直接按字典序从小到大的顺序递归一个一个的枚举. 注意:定义在dfs里的vis不能放在全局,否则会导致值的混用. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cst…
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1295 题解: 对每个点暴力跑一遍bfs,看能够到达的最远位置,这里如果有障碍物则距离为1,如果没有障碍物,则距离为0,用bfs跑距离<=t的所有点并更新答案. 代码: #include<iostream> #include<cstring> #include<cstdio> #include<utility> #include<queu…
Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. When Hogwarts school is in holiday, Harry Potter has to go back to uncle Vernon's home. But he can't bring his precious with him. As you know, uncle Ve…
题意: 给出n,m,代表微波炉有n个按钮,要求达到总时间为m 然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小 输出最小的步数与相差的最小值 要求,当总时间小于0时,时间为0,大于3600时,时间为3600 题意: 给出n,m,代表微波炉有n个按钮,要求达到总时间为m 然后给出n个数,代表n个按钮能增加的时间,问最少几步,能够使得按出的总时间大于等于要求的时间,并且相差最小 输出最小的步数与相差的最小值 要求,当总时间小于0时,时间为0,…
八数码问题是一个经典的人工智能问题.具体问题不累述了. 思路:由于存在多组测试数据,可以考虑“打表法“.所谓打表法,即枚举所有的初始情况,记录其到达终点的路径.而在这个题目中,顺序打表会调用很多次BFS,所以我们采用逆序打表,只要调用一次BFS. 代码如下: /*************map存路径,set判重,string存状态*****************/ /*********************暴力广搜 + STL **************************/ #inc…
http://acm.hdu.edu.cn/showproblem.php?pid=4462 题意:有一个n*n的地图,有k个空地可以放稻草人,给出每个空地可以放的稻草人属性,属性中有个R代表这个位置可以守卫的范围,问最少需要放多少个稻草人才可以守卫这个地图. 思路:可以状态压缩一样枚举所有的状态(为毛昨天想不到),然后就根据这个状态选择哪个空地接着暴力染色地图这样.注意k个地方是空地,不用守卫的. #include <cstdio> #include <cstring> #inc…
 Trees on the level UVA - 122  解题思路: 首先要解决读数据问题,根据题意,当输入为“()”时,结束该组数据读入,当没有字符串时,整个输入结束.因此可以专门编写一个readin()函数,类型设置为bool型,遇到第一种情况时返回true,遇到第二种情况返回false,主程序中只要发现readin返回false时就break,结束整个大循环. 接下来要建立二叉树,首先为二叉树编写一个结构体,然后根据字符串的输入情况来建树,如果是‘L’就往左走,走不动时建一颗新树,同样…
Description Input is the matrix A of N by N non-negative integers. A distance between two elements Aij and Apq is defined as |i − p| + |j − q|. Your program must replace each zero element in the matrix with the nearest non-zero one. If there are two…
B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/problem/B Description You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through t…
本文出自   http://blog.csdn.net/shuangde800 题目链接:点击打开链接 题目大意 有n个长度为m的二进制串,每个都是不同的. 为了把所有字符串区分开,你可以询问,每次可以问某位上是0还是1. 问最少提问次数,可以把所有字符串区分开来. 思路 f[s1][s2]: 表示提问的问题是{s1}集合,答案是{s2}时,还需要问几次才可以全部区分开 当问题集合为{s1}时, 如果还不能区分所有答案,那么就需要继续再问一个问题, 那么可以推出下一个问题的集合为: nextQu…
题意:有A个村庄,B个城市,m条边,从起点到终点,找一条最短路径.但是,有一种工具可以使人不费力的移动L个长度,但始末点必须是城市或村庄.这种工具有k个,每个只能使用一次,并且在城市内部不可使用,但在村庄内部可使用.另外,在城市或村庄内部的时间不计. 析:先预处理出来使用工具能到达的距离,这个可以用Floyd 来解决,然后f[i][u] 表示到达 u 还剩下 i 次工具未用,然后用bfs就可以很简单的解决. 代码如下: #pragma comment(linker, "/STACK:102400…
http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=101; int n,m; typedef unsigned long long ull; int A,B,C; int vis[maxn][maxn]; int ans[maxn][maxn][ma…