算法 acm
文章平均质量分 72
x-inda
这个作者很懒,什么都没留下…
展开
-
floy
如何求任意两点之间最短路径呢?通过之前的学习我们知道通过深度或广度优先搜索可以求出两点之间的最短路径。所以进行n2遍深度或广度优先搜索,即对每两个点都进行一次深度或广度优先搜索,便可以求得任意两点之间的最短路径。可是还有没有别的方法呢?我们来想一想,根据我们以往的经验,如果要让任意两点(例如从顶点a点到顶点b)之间的路程变短,只能引入第三个点(顶点k),并通过这个顶点k中转即a->k->b转载 2017-04-12 23:56:18 · 461 阅读 · 0 评论 -
二分_E
DescriptionWhen a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. When a thin rod is mounted on two solid walls原创 2016-08-10 16:24:43 · 388 阅读 · 0 评论 -
记忆化搜索
DescriptionFatMouse 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 each grid原创 2016-08-06 17:23:18 · 184 阅读 · 0 评论 -
dp_5
DescriptionThere is one very popular song called Jin Ge Jin Qu(). It is a mix of 37 songs, and is extremely long (11 minutes and 18 seconds) — I know that there are Jin Ge Jin Qu II and III, a原创 2016-08-06 17:09:57 · 270 阅读 · 0 评论 -
dp_4
DescriptionA numeric sequence of ai is ordered if a1 a2 aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 i1 i2 iK N. For e原创 2016-08-06 16:58:37 · 164 阅读 · 0 评论 -
dp_3
DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = another sequence Z = is a subsequence of X if there exists原创 2016-08-06 16:52:57 · 504 阅读 · 0 评论 -
dp_2
Description下图是个数字三角,请编写一个程序计算从顶部至底部某处一条路径,使得该路径所经过的数字总和最大。73 88 1 02 7 4 41. 每一步可沿左斜线向下或右斜线向下走;2. 13. 三角形中的数字为整数 0,1,……,99。4. 如果有多种情况结果都最大,任意输出一种即可。 输入:第一行一个整数N,代原创 2016-08-06 16:47:41 · 151 阅读 · 0 评论 -
dp_1
Description小时候我们都玩过爬楼梯的游戏:两人猜拳,赢了可向上爬一级,谁先到最高级则获胜。作为大学生,我们应该玩一个更有水平的游戏。现在一个人要上n级楼梯,每一步可以选择上一级或者上两级,但是不能后退。求上这n级楼梯的方案数。Input第一行只有一个整数T(1下面的T行每一行有一个整数n(1Outpu原创 2016-08-06 16:38:58 · 667 阅读 · 0 评论 -
规律题
DescriptionToday, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numb原创 2016-08-06 16:27:26 · 329 阅读 · 0 评论 -
二分图_1
DescriptionRecently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.Suppose the graph G is given. Subset A of its vertice原创 2016-08-06 16:09:27 · 327 阅读 · 0 评论 -
BFS_4
Description可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。 现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示原创 2016-08-10 16:37:24 · 276 阅读 · 0 评论 -
概率DP_1
DescriptionHzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probabil原创 2016-08-10 16:47:33 · 216 阅读 · 0 评论 -
概率dp_2
DescriptionIvan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possib原创 2016-08-10 16:53:33 · 157 阅读 · 0 评论 -
反转单链表的几种方法
反转单链表的几种方法 最近试着做一些笔试面试题,既是为来年找工作做准备,也可以做为数据结构和算法的复习笔记,就陆续发在这里吧,有需要的朋友可以看一下,如果有没考虑周全的地方欢迎指正。 先来一个最常见的题目:反转单链表。假设单链表的数据结构定义如下: typedef struct LNode{ int转载 2016-10-08 13:56:32 · 198 阅读 · 0 评论 -
acm-位运算
这个暑假的培训发现好多大牛的代码都包含位运算,而且今年面试中位运算也是必备技能,所以就来一次大总结位运算是指按二进制进行的运算。在系统软件中,常常需要处理二进制位的问题。C语言提供了6个位操作运算符。这些运算符只能用于整型操作数,即只能用于带符号或无符号的char,short,int与long类型。C语言提供的位运算符列表:运算符 含义 描述1.& 按位与 如果两个相应转载 2016-08-15 11:33:32 · 1952 阅读 · 0 评论 -
stl_1
DescriptionYou are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i j) that ai + aj is a power of 2 (i. e. some integer xexists so that ai + aj = 2x).Inp原创 2016-08-10 17:21:34 · 334 阅读 · 0 评论 -
最大公约数_1
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive原创 2016-08-10 17:17:55 · 802 阅读 · 0 评论 -
0/1背包_1
DescriptionRecently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud原创 2016-08-10 17:11:53 · 234 阅读 · 0 评论 -
贪心_4
DescriptionA number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.You a原创 2016-08-10 17:07:07 · 257 阅读 · 0 评论 -
区间dp_3
DescriptionThe multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points原创 2016-08-10 17:01:47 · 382 阅读 · 0 评论 -
区间dp_2
DescriptionWe give the following inductive definition of a “regular brackets” sequence:the empty sequence is a regular brackets sequence,if s is a regular brackets sequence, then (s) and [s]原创 2016-08-10 16:59:59 · 164 阅读 · 0 评论 -
区间dp_1
Description现在有n堆石子,第i堆有ai个石子。现在要把这些石子合并成一堆,每次只能合并相邻两个,每次合并的代价是两堆石子的总石子数。求合并所有石子的最小代价。Input第一行包含一个整数T(T每组数据第一行包含一个整数n(2第二行包含n个正整数ai(aiOutput每组数据仅一行,表示最原创 2016-08-10 16:57:56 · 392 阅读 · 0 评论 -
贪心_3
Descriptionzichen 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 zichen hands in the homew原创 2016-08-06 15:54:25 · 177 阅读 · 0 评论 -
贪心_2
Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building.原创 2016-08-05 17:28:05 · 165 阅读 · 0 评论 -
DFS_3
Description速算24点相信绝大多数人都玩过。就是随机给你四张牌,包括A(1),2,3,4,5,6,7,8,9,10,J(11),Q(12),K(13)。要求只用'+','-','*','/'运算符以及括号改变运算顺序,使得最终运算结果为24(每个数必须且仅能用一次)。游戏很简单,但遇到无解的情况往往让人很郁闷。你的任务就是针对每一组随机产生的四张牌,判断是否有解。我们另外规定,整原创 2016-08-04 16:27:45 · 213 阅读 · 0 评论 -
DFS_2
DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. No原创 2016-08-03 23:38:44 · 159 阅读 · 0 评论 -
DFS_1
Description在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,原创 2016-08-03 23:30:02 · 614 阅读 · 0 评论 -
快速幂取模
DescriptionPeople are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathe原创 2016-08-03 23:16:16 · 327 阅读 · 0 评论 -
快速幂取模
DescriptionGiven a positive integer N, you should output the most right digit of N^N. InputThe input contains several test cases. The first line of the input is a single integer T原创 2016-08-03 23:08:44 · 223 阅读 · 0 评论 -
二分_E
DescriptionThe SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b + c + d = 0 .原创 2016-08-03 22:55:56 · 208 阅读 · 0 评论 -
二分_D
DescriptionMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my par原创 2016-08-03 22:48:49 · 202 阅读 · 0 评论 -
二分_C
Description— The Brother of mine, the Head of Monastic Order wants to know tomorrow about the results long-term researches. He wants to see neither more nor less than the Summering Machine! Even m原创 2016-08-03 22:40:57 · 157 阅读 · 0 评论 -
二分_B
Description现在,给出等式8* X^4+ 7* X^3+ 2* X^2+ 3 * X +6= Y,请找出他在0和100之间的解(包含0和100)。现在,请你试试运气。。。。 Input输入的第一行包含一个整数T(1 Output对于每个测试用例,如果有解,你应该输出一个实数(精确到小数点后4位,四舍五入),如果在0到原创 2016-08-03 22:34:21 · 298 阅读 · 0 评论 -
规律题_1
DescriptionN children standing in circle who are numbered 1 through N clockwise are waiting their candies. Their teacher distributes the candies by in the following way:First the teacher gives原创 2016-08-04 16:52:26 · 342 阅读 · 0 评论 -
三分_1
DescriptionNow, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 Can you find the minimum value when x is between 0 and 100.InputThe first line of the input contains原创 2016-08-04 16:59:35 · 145 阅读 · 0 评论 -
二分_F
Description一个杯子装了很多水,可以把杯子看成圆台,并给出圆台的底面半径,顶部半径,高还有水的体积,求水的高度。Input输入包括T组数据 每组数据包含一行,并且有四个数r, R, H, V代表圆台底部半径,顶部半径,高度和水的体积。 1. T ≤ 20. 2. 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000原创 2016-08-04 17:11:36 · 366 阅读 · 0 评论 -
贪心_1
DescriptionToday the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi c原创 2016-08-05 17:18:04 · 154 阅读 · 0 评论 -
三分_3
DescriptionIn the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate the harvest every year. But there is one thing you may not know that they hate walking原创 2016-08-05 17:07:49 · 272 阅读 · 0 评论 -
DFS_6
DescriptionZty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solve a problem that is e原创 2016-08-05 16:36:35 · 279 阅读 · 0 评论 -
BFS_3
DescriptionAngel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M Angel's friends want to save Angel. Their task is: approach Angel. We assu原创 2016-08-05 13:32:55 · 230 阅读 · 0 评论