算法竞赛入门经典紫书
文章平均质量分 80
叶子心情你不懂
帅哥
展开
-
3.1 SCORE UVA1585
ScoreDescriptionThere is an objective test result such as ``OOXXOXXOOO". An `O' means a correct answer of a problem and an `X' means a wrong answer. The score of each problem of this tes原创 2017-11-30 08:41:16 · 234 阅读 · 0 评论 -
Tour Uva1347(DP)
刘汝佳给这道题的分析真的妙。太大佬了。1.“从左到右再回来”不太方便思考,可以改成:两个人同时从最左点出发,沿着两条不同的路径走,最后都走到最右点,且除了起点和终点外其余每个点恰好被一个人经过。 这样,就可以用d(i,j)表示第一个人走到i,第二个人走到j,还需要走多长的距离。 这样换个方式思考就大大减少了复杂度!2.好像很难保证两个人不会走到相同的点。 例如,计算原创 2018-02-05 02:20:47 · 169 阅读 · 0 评论 -
UVA1626 Bracketssequence(括号匹配)
Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are r原创 2018-02-09 23:31:26 · 209 阅读 · 0 评论 -
几道简单dp题目。
两道DP后打印的:一。劲歌金曲(Jin Ge Jin Qu [h]ao, Rujia Liu's Present 6, UVa 12563)题目描述:(If you smiled when you see the title, this problem is for you ^_^)For those who don’t know KTV, see: http://en.wikip原创 2018-02-07 00:43:46 · 893 阅读 · 0 评论 -
Color Length UVA1625(DP)
这题状态转移方程倒是很好想,就是那个预处理有点麻烦,没办法最后还是百度......百度后还是T......借鉴的几个博客:点击打开链接 点击打开链接预处理方面,knm[i][j]表示n,m两个序列n取走i个m取走j个后已经开始且没有结束的颜色的花费.刘汝佳标程里处理是先在i为0时扫一遍j,然后每个knm[i][j]的j部分就由上一层计算得来.第二个卡我的点是me原创 2018-02-08 17:35:39 · 140 阅读 · 0 评论 -
The Morning after Halloween
You are working for an amusement park as an operator of an obakeyashiki, or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which ar原创 2018-04-14 19:18:25 · 325 阅读 · 0 评论 -
二进制枚举子集
《算法竞赛入门经典》上的,真厉害。用数字s的二进制位来代表集合s的元素。#include void print_subset(int n, int s){ for(int i = 0; i < n; i++){ if(s & (1 << i)) printf("%d", i); } printf("\n");}原创 2018-04-02 20:46:25 · 188 阅读 · 0 评论 -
Krypton Factor(UVA129)
You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the contestants are tested o原创 2018-04-02 22:25:27 · 210 阅读 · 0 评论 -
八数码问题(宽搜状压)
八数码问题。 编号为1~8的8个正方形滑块被摆成3行3列(有一个格子留空),如图7-14所示。 每次可以把与空格相邻的滑块(有公共边才算相邻)移到空格中,而它原来的位置就成为了新的空格。 给定初始局面和目标局面(用0表示空格),你的任务是计算出最少的移动步数。 如果无法到达目标局面,则输出-1。 宽搜以求最短路。状压以判重。判重书上介绍了三种。我添加了一种差不多的。搜索只是简单的宽搜,但是这个状态...原创 2018-04-05 13:48:36 · 397 阅读 · 0 评论 -
UVA10603 FILL(宽搜)
There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater than 200). The first and the second jug are initially empty, while the third is completely filled原创 2018-04-05 15:06:59 · 117 阅读 · 0 评论 -
Image Is Everything UVA - 1030(思维体操)
Your new company is building a robot that can hold small lightweight objects. The robot will have the intelligence to determine if an object is light enough to hold. It does this by taking pictures of...原创 2018-05-10 21:26:07 · 216 阅读 · 0 评论 -
Cutting Sticks UVA 10003(区间DP)
d(i,j)是第i个和第j个节点之间最优切割法.这个状态转移方程太适合写记忆化搜索了,但是写迭代就有点gg.刘汝佳书上说这样的"正确的方法是按照j-i递增的顺序递推,因为长区间的值依赖于短区间的值 "那么就算区间长度为0,1,2,3.....这样迭代下去.还是第一次写记忆化搜索.1.以区间分解分割(好像是理所当然).2.存区间节点数组的边界要注意.3.我输出少了个'.'号.原创 2018-02-09 01:50:58 · 147 阅读 · 0 评论 -
The Tower of Babylon(Uva437)(DP)
刚接触动态规划,一开始写也挺顺,但是犯了错误。这题可以写成DAG的记忆化搜索,这种写法我没写过,有空来补上。先推荐下下别人的代码。代码链接:点击打开链接 我是写成递推形式的,但是设计状转移方程时犯了错误,我一开始的核心代码:for(int i = 0; i < k; i++){ dp[i] = date[i].c; for(int j = 0; j <原创 2018-02-04 00:27:28 · 147 阅读 · 0 评论 -
3.2 Molar Mass UVa1586
An organic compound is any member of a large class of chemical compounds whose molecules contain carbon. The molar mass of an organic compound is the mass of one mole of the organic compound. The mola原创 2017-11-30 08:50:29 · 207 阅读 · 0 评论 -
3.3 Digit Counting UVA1225
DescriptionTrung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 toN(1 N . After that, he counts the原创 2017-11-30 09:07:31 · 208 阅读 · 0 评论 -
3.4 Periodic Strings UVA455
这题我记得是记录每个和首字母相同的字母的位置,从首字母一一的和以后的字母匹配,大概就是比如abcabcabcabc就位置1和4比较,然后2和5,然后3和6有个bug就是abcababcabab这样的也能扫描到最后,所以最后卡了个倍数A character string is said to have period k if it can be formed by concatenating原创 2017-11-30 09:18:11 · 188 阅读 · 0 评论 -
3.5 Puzzle UVA227
题目链接:点击打开链接我当时取得函数名真奇葩初始化二维数组我怎么会用getchar的,,,,难道是防空格吗,怎么着还有gets啊#include #include char she[6][6];int x, y;int ope(int com);void psh(int k, int kase);void swash(int i1, int j1, int i2,原创 2017-11-30 09:34:30 · 130 阅读 · 0 评论 -
3.6 Crossword Answers UVa232
题目链接:点击打开链接我记得是卡在输出上了,题目没读清楚,竖着输出也要有横着的数字顺序两个数组,一个记录输入,一个记录数字#include #include #define MAX 20int r, c, kase = 0;int she[MAX][MAX + 1] = {'\0'}, num[MAX][MAX + 1];void pri();int main(){原创 2017-11-30 09:42:43 · 201 阅读 · 0 评论 -
3.7 DNA Consensus String UVA1368
题目链接:点击打开链接本来以为是输出其中一个,原来是输出新组合的,英语是硬伤#include #include #define MAX 20int r, c, kase = 0;int she[MAX][MAX + 1] = {'\0'}, num[MAX][MAX + 1];void pri();int main(){ while((scanf("%d",&r原创 2017-11-30 09:52:03 · 131 阅读 · 0 评论 -
3.8 Repeating Decimals UVA202
题目链接:点击打开链接算法就是判断余数,余数一出现和第一个一样的就break,当然那时候好像写的复杂了点#include #include int expa[3001] = {'\0'};//1000太少了,一开始越界了int mod[3001] = {'\0'};int m, n;//memset(exp , '\0', sizeof(exp) );//memset(m原创 2017-11-30 10:00:35 · 126 阅读 · 0 评论 -
3.9 All in All UVa 10340
题目比较水,不过数据真是坑,那么大#include #include char s[1000000] = {'\0'}, t[1000000] = {'\0'};//1000,3000,10000。。。为啥要这么大才够int main(){ while( scanf("%s", s) != EOF ) { scanf("%s", t);原创 2017-11-30 10:06:04 · 121 阅读 · 0 评论 -
3.10 Box UVA1587
直接暴力if,反正只要判断三个面就行了要是想写的漂亮点可以排个序判断,套个循环读入什么的#include int main(){ struct rec { int x; int y; }a, b, c, d, e, f, g[6]; int i, j; while( scanf("%d",&a.x) != EO原创 2017-11-30 10:16:16 · 156 阅读 · 0 评论 -
A Spy in the Metro(Uva1025,2003WorldFinal)(DP)
时间是单向流逝的,是一个天然的“序”。 影响到决策的只有当前时间和所处的车站,所以可以用d(i,j)表示时刻i,你在车站j(编号为1~n),最少还需要等待多长时间。 边界条件是d(T,n)=0,其他d(T,i)(i不等于n)为正无穷。 有如下3种决策。决策1:等1分钟。决策2:搭乘往右开的车(如果有)。决策3:搭乘往左开的车(如果有)。(来自《算法竞赛入门经原创 2018-02-03 18:49:41 · 180 阅读 · 0 评论 -
Floating-Point Numbers UVA - 11809
觉得有点难、、、//(1 - 2 ^ (-m - 1)) * 2 ^ (2 ^ e - 1) = A * 10 ^ B//x = (1 - 2 ^ (-m - 1))//y = (2 ^ e - 1)//x * 2 ^ y = A * 10 ^ B//logx + y * log2 = logA + B然后打表就行了。#include <cstdio>#incl...原创 2018-09-24 23:28:14 · 185 阅读 · 0 评论