自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

peach_yang的博客

算法 ACM

  • 博客(60)
  • 收藏
  • 关注

原创 Coupons and Discounts(细节题)

Question:题目详情(http://codeforces.com/problemset/problem/731/B) 题目大意:一个人买披萨,有n天,每天都要ai个披萨,她是一家店的会员,可以在一天同时使用无数张第一种和第二种优惠券,第一种优惠券是一天买两个可用,第二种是连续两天都买一个可用(例如第一天买了一个,第二天也必须买一个才可以用),问他是否在每天都不多买的情况下使用优惠券买到披萨

2016-10-17 22:25:47 450

原创 Patrol Robot(BFS)

Question:题目详情(http://vjudge.net/contest/135927#problem/B) 题目大意:从一个矩阵的左上角到右下角的最短步数,但方阵中有一些有障碍,机器人只能连续穿过最多k个墙,如不能则输出-1 解题思路:开始时就想到的事bfs,但要考虑穿过的墙数目,所以就不知道怎么做了,但后来想到可以通过vis三维变量来标记,第三维表示到这个点的各个墙数是否被访问过,这样

2016-10-17 22:05:12 381

原创 Knight Moves(BFS)

Question:题目详情(http://vjudge.net/contest/135927#problem/A) 题目大意:在一个棋盘上横坐标为1~8,纵坐标为a~g,给你一个起点高一个终点,让你用中国象棋的马走日算出起点到终点的最短步数 解题思路:这就是一道简单的bfs的题,只是跟以往的不同的是这次是“马走日”,其余的没什么不同#include <iostream>#include <cs

2016-10-17 21:47:10 661

原创 Paintball(dfs判断连通)

Question:题目详情(http://vjudge.net/contest/134361#problem/C) 题目大意:有一个1000*1000的方阵(建立坐标),这之间有一些士兵有具体的坐标,并且具有一定的攻击半径,现你要从最左边进入,途中避开所有的士兵(不被攻击),从最右边出,如果有多解则输出离北边最近的额坐标 解题思路:可以把士兵看成一个个圆,看成池塘的石头,如果能从池塘的最北边走石

2016-10-09 23:50:12 298

原创 Parentheses Balance(栈)

Question:题目详情(http://vjudge.net/contest/134361#problem/D) 题目大意:只有()[] 四种字符,空串为平衡,()[]都为平衡,平衡里面嵌套平衡也是平衡的 解题思路:用一个栈遇到’ [ ‘,’(‘时就推入遇到’ )” ] ‘时就与栈顶匹配,如果能匹配就婆婆,最终判断栈是否为空,如为空则平衡,否则不平衡。但注意:))))]]]这种情况用上述方法

2016-10-09 23:31:54 331

原创 S-Trees(二叉树)

Question:题目详情(http://vjudge.net/contest/134361#problem/E) 题目大意:有一个n层的满二叉树,每个子节点都对应了一个确定的值(共2^n个),有m个访问值,每个访问值由n个0,1组成,0表示走左子节点,1表示走右子节点,这样每个访问值都对应了原二叉树的子节点的一个确定的值,最后输出m个访问值 解题思路:先用一个数组保存下2^n个节点的值,然后将

2016-10-09 23:19:58 1385

原创 Tree Recovery(二叉树建树,后序遍历)

Question:题目详情(http://vjudge.net/contest/134361#problem/F) 题目大意:给你一棵树的前序遍历和中序遍历,让你输出后序遍历 解题思路:就单纯的建树并输出后序遍历即可#include <iostream>#include <cstdio>#include <cstring>using namespace std;char q[30],z[

2016-10-09 17:21:37 500

原创 UmBasketella(弱校联盟十一专场)

Question:题目详情(https://www.bnuoj.com/v3/contest_show.php?cid=8507#problem/G) 题目大意:给你一个圆锥的表面积(要算上底面积),要你算最大的体积即高和底面半径 解题思路:(http://img.blog.csdn.net/20161007190817137)#include <iostream>#include <cstd

2016-10-07 19:11:05 286

原创 Blocks(弱校联盟十一专场)

Question:题目详情(https://www.bnuoj.com/v3/contest_show.php?cid=8507#problem/D) 题目详情:要给n个街区涂色,用红,蓝,绿,黄四种颜色,每个街区任意图色,但必须保证红色和绿色是偶数,问有多少种图法 解题思路:我是找出了递推公式,换个思路,如果n为奇数,则先选出一个街区图其他两种颜色,剩下的2*Cn~1*(C(n-1)~0+C(

2016-10-07 18:12:42 267

原创 Basic Data Structure(弱校联盟十一专场)

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1008&cid=729) 题目大意:有一个栈有四个操作∙ PUSH x (x must be 0 or 1) ∙ POP(弹出栈顶元素) . REVERSE( 置逆) ∙ QUERY(根据与非的出最终答案) 与非:0~1->1;0~0-

2016-10-06 21:34:36 309

原创 Mr. Frog’s Game(弱校联盟十一专场(连连看))

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=729) 题目大意:这是一道连连看的题,只能消掉最多拐弯两次的两个物体,只需找到一对即可 解题思路:遍历四边,看有没有相同的,再遍历中间部分的有没有两个相邻相同的即可,虽然我写的比较复杂,但总体来说过得了,没什么问题#include

2016-10-06 21:07:30 632

原创 Mr. Frog’s Problem(弱校联盟 十一专场)

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1003&cid=729) 题目大意:A≤C≤B,A≤D≤B and A/B+B/A≤C/D+D/C,z找到满足关系式的c,d对数 解题思路:其实经过一些实验你会发现,如果A,B相等,那满足式子的只有一对,即c,d,与a,,b相等,如果两个数不相等,则

2016-10-06 20:49:06 692

原创 Minimum’s Revenge(弱校联盟十一专场)

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=729) 题目大意:给你1~n,任意两点的权值为他们的乘积,问连接说有的点最小需要的权值和为多少 解题思路:这道题有点最小生成树的感觉,但数据太大,所以找其他方法,起始仔细观察,任意一点都与1相连权值是最小的#include <cst

2016-10-06 20:39:51 449

原创 Harmonic Value Description(长春重现赛)

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1006&cid=728) 题目大意:给你1~n,求gcd(a[i],a[i+1])的和,将和进行排列,让你输出gcd和第k小的那个排列(有多解输出一个即可) 解题思路:因为连续的数间的gcd为1,每组数的gcd和至少为n-1,要求出第k小的数,先找到

2016-10-05 14:33:58 283

原创 Triangle(长春 重现赛(斐波拉契数列))

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=728) 题目大意:有1~n的数,问你至少拿掉几个数才能使剩下的数不能组成三角形 解题思路:三角形两边之和大于第三边,按照这个规则,找到第二第三大的两边等于第一大的边,这样数列中就不可能组成三角形了(1,2,3,5,8,13。。。),

2016-10-05 14:22:00 233

原创 Fraction(长春重现赛)

Question:题目详情(http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=728) 题目大意:给你一个公式法f(x)=b[n]/(a[n]+f(x+1)),边界值为f(n)=b[n]/a[n],求f(1),并且输出分数(分子和分母分别输出) 题解思路:第一想到的就是递归,可以用两个全局变量p,q 来分别表示

2016-10-05 12:17:05 242

原创 Parentheses(弱校联盟十一专场)字典序

Question:题目详情(D题)(https://acm.bnu.edu.cn/v3/statments/jag2016.pdf) 题目大意:“()”称为平衡的,平衡里面嵌套平衡也是平衡的,现在给你一个数,要求你输出一个最短字符串经过移动这么多步就可以达到平衡状态(而且这个字符串的字典序最小,规定‘(’的字典序小于‘)’) 解题思路:经过我们一番推导会发现找到一些状态,例如:1->”)(“;

2016-10-04 10:21:10 326

原创 Coins(弱小联盟十一专场)

Question:题目详情(https://www.bnuoj.com/bnuoj/contest_show.php?cid=8520#problem/101259) 题目大意:有a0,a1,a2枚面值为1,2,3的硬币,问能组成多少种面值 解题思路:只是一道找规律的题,可以考虑面值为1的数量如果为0,只有2,3时(都不为0):只有面值为2的只有一枚是为1+2*a3(加1是因为有个2,2*a3是

2016-10-03 10:50:45 290

原创 UVA 1572 Self-Assembly(拓扑排序)

Question:题目详情(http://vjudge.net/contest/133965#problem/F) 题目大意:有些种类的正方形,每条边有两个符号,‘00‘’不能与任何边相连,只有字母相同,“+-”相反才能相连,让判断是否用这些已有的正方形铺成无限大的平面 解题思路:将字母装华为数字例如A+A-转化为2n,2n+1,这样如果一个正方形x(A+)能和另一个正方形y(A-)相连,则正方

2016-09-30 07:35:54 429

原创 UVA 10562 Undraw the Trees

Question:题目详情(http://vjudge.net/contest/133965#problem/D) 题目大意:让你根据输入建图,并输出前序遍历,每个节点下有’|’ 则证明有子树,每棵树以‘#’结束 解题思路:如果一个节点下有‘|’则找到它下两行最左边的‘-’符号,从哪里访问,关键是读入当时学习了一下#include <iostream>#include <cstdio>#in

2016-09-29 23:50:10 196

原创 UVA 10129 Play on Words(欧拉回路)

Question:题目详情(http://vjudge.net/contest/133965#problem/C) 题目大意:有很多单词,要你把他们排列成一个单词的末尾为下一个单词的首字母,问这么排列是否可行 解题思路:根据题意建立一个无向图(一个单词的首尾字母关系),判断图中是否存在欧拉回路,判断欧拉路径的方法两个因素:1。图必须连通(并查集,dfs可执行),2。出入度数必须满足每个节点的入度

2016-09-29 23:06:12 255

原创 UVA 572 Oil Deposits(DFS)

Question:题目详情(http://vjudge.net/contest/133965#problem/B) 题目大意:有一个矩阵,矩阵中的只要相邻或者对角线的‘@’符号都可以算作一个连通集,问有多少个连通集 解题思路:这道题是典型的dfs#include <iostream>#include <cstdio>#include <cstring>#include <string>#

2016-09-29 22:37:57 215

原创 UVA 297 Quadtrees(四叉树)

Question: A quadtree is a representation format used to encode images. The fundamental idea behind the quadtree is that any image can be split into four quadrants. Each quadrant may again be split in

2016-09-27 21:55:08 357

原创 UVA 699 The Falling Leaves(二叉树)

Question: Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on the trees, followed quickly by the falling leaves accumulating under the trees. If the sa

2016-09-27 21:34:59 324

原创 UVA 839 Not so Mobile(二叉树经典题)

Question; Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires suspending colourfull things. This kind of mobile is usually found hanging over cra

2016-09-27 21:22:20 246

原创 UVA 548 Tree(二叉树建树)

Question: You are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least value from the root of the binary tree to any leaf. The value of a path i

2016-09-27 21:09:44 311

原创 UVA 679 Dropping Balls(二叉树)

Question: A number of K balls are dropped one by one from the root of a fully binary tree structure FBT. Each time the ball being dropped first visits a non-terminal node. It then keeps moving down,

2016-09-27 20:59:08 215

原创 UVA 12657 Boxes in a Line(双向链表)

Question: 12657 Boxes in a Line You have n boxes in a line on the table numbered 1 … n from left to right. Your task is to simulate 4 kinds of commands: • 1 X Y : move box X to the left to Y (ignor

2016-09-08 14:06:02 231

原创 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(破损的键盘(又名:悲剧的文本))(链表)

Question: Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that sometimes the “home” key or t

2016-09-08 13:50:51 384

原创 UVA 442 Matrix Chain Multiplication(栈)

Question: Matrix Chain Multiplication Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplication is associative, the order in which mult

2016-09-08 13:32:40 241

原创 UVA 514 Rails(栈)

Question: Rails There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time.

2016-09-08 13:21:17 229

原创 Gym 100712F Travelling Salesman

Question: After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends most of his time travelling between different cities. He decided to buy a new car to help him in his job, but he h

2016-09-05 23:00:01 310

原创 UVALive 6832 Bit String Reordering

Question: You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required.

2016-09-05 22:50:43 369

原创 UVALive 6834 Shopping(开箱拿钥匙题型)

Question: Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop has one do

2016-09-05 22:42:04 345

原创 HDU 1078 FatMouse and Cheese(记忆化)

Question: Description FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At e

2016-08-30 11:03:55 364

原创 HDU 1025 Constructing Roads In JGShining's Kingdom(LIS)

Question: Description JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich

2016-08-30 10:55:09 332

原创 HDU 1978 How many ways

Question: Description 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m)。游戏的规则描述如下: 1.机器人一开始在棋盘的起始点并有起始点所标有的能量。 2.机器人只能向右或者向下走,并且每走一步消耗一单位能量。 3.机器人不能在原地停留。 4.当机器人选择了一条可行路径后,当他走到这条路径的终点时,他将只有终点所标记

2016-08-30 10:38:31 301

原创 HDU 1789 Doing Homework again

Quetions: Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands i

2016-08-30 10:16:07 263

原创 HDU 1058 Humble Numbers

Question: Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, … shows the first

2016-08-29 17:17:40 333

原创 POJ 1458 Common Subsequence

Question: Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, …, xm > another sequence Z = < z1, z2, …, zk

2016-08-29 16:57:31 310

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除