HDOJ代码
文章平均质量分 76
altair21
这个作者很懒,什么都没留下…
展开
-
HDOJ--1061--Rightmost Digit
Problem 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 in原创 2013-05-20 19:43:57 · 534 阅读 · 0 评论 -
HDOJ--4869--Turn the pokers【组合数学+快速幂】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4869题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次翻牌后牌的朝向有多少种情况。这道题在比赛时我们只开了个头,却无从下手。我看了网上的解题报告,说的都比较简单,对于我这名菜鸟来说也想了比较长的时间才想明白,所以我想写的清楚原创 2014-07-24 22:50:21 · 1013 阅读 · 0 评论 -
HDOJ--1312--Red and Black【DFS】
Problem DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adja原创 2013-05-20 19:48:29 · 890 阅读 · 0 评论 -
HDOJ--2544--最短路【最短路】
Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input输入包括多组数据。每组数据第一行是两个整数N、M(N输入保证至少存在1条商店到赛场的路线。原创 2013-05-20 19:29:33 · 657 阅读 · 0 评论 -
HDOJ--4791--Alice's Print Service
题意:现在你要打印一些东西,比如需要99张纸,打印100张以下时话费10元每张,100张及100张以上时需要5元每张,此时你可以选择打印100张,使得花费更小。现给一个数字n,表示n个区间段,然后有s1,p1,s2,p2......sn,pn,表示打印纸张大于等于s1而小于s2时,每张纸话费p1元,现有m个询问,问每次给你x张纸,所需的最小花费是多少。思路:可以从后往前做一个O(n)的原创 2014-07-27 23:54:47 · 920 阅读 · 0 评论 -
HDOJ--4893--Wow! Such Sequence!【线段树+单点、区间更新】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4893题意:给你一个长度n的数列,初始都为0,有三种操作,第一种给第k个位置的数加d,第二种是查询区间 [l , r] 的总和,第三种是使区间 [l , r] 的值改为离它最近的那个斐波那契数的值。我刚开始用sum数组存储节点的值,第三种操作是个区间更新,但是区间更新的值不一样,我就想当然的原创 2014-07-29 19:12:17 · 929 阅读 · 0 评论 -
HDOJ--4781--Assignment For Princess【构造有向图】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4781题意:给你两个数,n代表顶点个数,m代表边数,要你建一个图,要求:1. 有向图,且两个点之间最多只有一条边。2. 边的权值大小为1~m,每个值只能用一次。3. 任意一个点都可以到达其余各个顶点。4. 任意一个环的边上权值之和是3的倍数。5. 不存在自身环。思路:先从原创 2014-08-04 16:41:49 · 809 阅读 · 0 评论 -
HDOJ--2795--Billboard【线段树】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795题意:在一块高h,宽w的木板上贴广告,广告高为1,宽为wi,每次都从最左上方贴,没位置再向下挪。按顺序输入广告宽度,输出它所在的行数,贴不下输出-1。思路:这道题一开始看不出来是线段树,但是如果把木板转90°,就是一个很明显的线段树了,把原来的高度当作线段树的宽度,然后维护原来的宽度,更新直接在查询中处理原创 2014-07-21 20:18:40 · 618 阅读 · 0 评论 -
HDOJ--4786--Fibonacci Tree【生成树】
题意:给出n个点,m条边,和边的信息。边有两种颜色,白色和黑色,现要求构造一个生成树,看能否满足白边的数量是斐波那契数。这道题比赛的时候,小白想到了一种方法:按边颜色排序后,先用白边优先建树,求出最大白边最大个数maxm,再用黑边优先建树,求出白边最小个数minm,看这两个范围内是否存在斐波那契数。听上去感觉还挺有道理,但是不知道怎么证明正确性,后来想想,生成树构造完之后,再添加任原创 2014-08-04 11:51:06 · 889 阅读 · 0 评论 -
HDU--3746--Cyclic Nacklace【KMP】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746题意:在一个字符串后最少加几个字符才能使这个字符串是某个串重复两次而得。思路:借助了这篇博文的结论:传送门结论:len-next[i]为此字符串的最小循环节(i为字符串的结尾),另外如果len%(len-next[i])==0,此字符串的最小周期就为len/(len-next[i]原创 2014-09-05 23:02:07 · 587 阅读 · 0 评论 -
HDUOJ--4046--Panda【线段树】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046题意:题目先来了一大段情书,看的我莫名其妙,然后来了一段情话原创 2014-08-08 23:45:15 · 1025 阅读 · 0 评论 -
POJ--4973--A simple simulation problem.【线段树】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4973题意:有一段数字,长度n,数字为1~n,有两种操作,第一种是使区间[l,r]内的所有数字变成两个,长度n随之增大,第二种操作是查询区间[l,r]中相同的数字最多有多少个。思路:比赛时扫了一眼,看区间要扩大,没有细想就觉得线段树做不了,而且当时没有人交这道题就没管了,然后看解题报告居然真原创 2014-08-22 14:54:16 · 920 阅读 · 0 评论 -
HDUOJ--2121--Ice_cream’s world II【朱刘算法】不定根最小树形图
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2121题意:n个顶点,m条边,求从某一点起建立有向图最小生成树并且花费最小,输出最小花费和根节点下标。思路:这道题根是不确定的,我们可以先假设一个根,从这个根出发到任何一点的距离(sum)都比原图总权值还大,这样保证了虚拟的边不会是最小入边,也为之后判断是否生成了最小树形图提供方便,从这个点原创 2014-08-10 16:25:06 · 876 阅读 · 0 评论 -
HDUOJ--4888--Redraw Beautiful Drawings【isap】网络流+判环
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4888题意:原创 2014-08-23 00:17:52 · 1022 阅读 · 0 评论 -
HDU--2586--How far away ?【LCA】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586题意:一棵有边权的树,问任意两点间的长度是多少。思路:做LCA题目看到的这道题,就用LCA做了,其实只用LCA的递归部分就能做这道题了。用一个数组dis记录根节点到每个节点的距离,则任意两节点a、b间的距离就是dis[a]+dis[b]-2*dis[lca(a,b)]。我用ve原创 2014-09-15 22:31:43 · 878 阅读 · 0 评论 -
HDOJ--4821--String【字符串hash】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821题意:给一个字符串,选m个长度为l的子串组成新的串,要求这m个子串互不相同,问有多少种组合。字符串hash题目,以前没做过,做这道之前还用bkdrhash做了两道简单的题目,POJ1200和HDU1800。用base数组记录乘了几个seed,base[i]表示seed^i,这个数组原创 2014-07-24 01:42:58 · 1235 阅读 · 0 评论 -
HDU--1054--Strategic Game【最小点覆盖】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054题意:一个熊孩子玩策略游戏,他需要用最少的士兵守卫最多的道路,如果这个顶点有士兵,则和这个点相连的所有边都会被保护,问保护所有的道路最少需要的士兵数量。思路:这实际上就是一个最小点覆盖,二分图的最小点覆盖 == 最大匹配,这不是一个二分图,我们把n个点扩成2 * n个,把他转换为二分图原创 2014-10-18 23:11:08 · 741 阅读 · 0 评论 -
HDOJ--2136--Largest prime factor【筛法】
Problem DescriptionEverybody knows any number can be combined by the prime number.Now, your task is telling me what position of the largest prime factor.The position of prime 2 is 1, prime 3 i原创 2013-05-20 19:40:43 · 758 阅读 · 0 评论 -
HDOJ--2181--哈密顿绕行世界问题【DFS】
Problem Description一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m=1.m=0退出. Output输出从第m个城市出发经过每个城市1次原创 2013-05-19 20:00:37 · 670 阅读 · 0 评论 -
HDOJ--1596--find the safest road【最短路】
Problem DescriptionXX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的通道P 的安全度为Safe(P) = s(e1)*s(e2)…*s(ek) e1,e2,ek是P 上的边 ,现在8600 想出去旅游,面对这这么多的路,他想找一条最安全的路。但是原创 2013-06-01 20:55:07 · 562 阅读 · 0 评论 -
HDOJ--1213--How Many Tables【并查集】
Problem DescriptionToday is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the fri原创 2013-05-27 00:12:13 · 624 阅读 · 0 评论 -
HDOJ--2199--Can you solve this equation?【二分法】
Problem DescriptionNow,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;Now please try your lucky. InputThe first line of the inp原创 2013-05-20 19:56:51 · 698 阅读 · 0 评论 -
HDOJ--2602--Bone Collector【背包问题】
Problem DescriptionMany years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grav原创 2013-07-11 11:00:06 · 542 阅读 · 0 评论 -
HDOJ--1241--Oil Deposits【DFS】
Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates原创 2013-05-20 19:52:36 · 621 阅读 · 0 评论 -
HDOJ--1711--Number Sequence【KMP】
Problem DescriptionGiven two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] =原创 2013-07-09 15:12:39 · 531 阅读 · 0 评论 -
HDOJ--1114--Piggy-Bank【背包问题】
Problem DescriptionBefore ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). Th原创 2013-07-11 14:37:43 · 519 阅读 · 0 评论 -
HDOJ--1872--稳定排序【排序算法】
Problem Description大家都知道,快速排序是不稳定的排序方法。如果对于数组中出现的任意a[i],a[j](i某高校招生办得到一份成绩列表,上面记录了考生名字和考生成绩。并且对其使用了某排序算法按成绩进行递减排序。现在请你判断一下该排序算法是否正确,如果正确的话,则判断该排序算法是否为稳定的。 Input本题目包含多组输入,请处理到原创 2013-07-10 11:25:04 · 670 阅读 · 0 评论 -
HDOJ--1856--More is better【并查集】
More is betterTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)Total Submission(s): 8985 Accepted Submission(s): 3354Problem DescriptionMr Wang原创 2013-05-26 23:52:28 · 457 阅读 · 0 评论 -
HDOJ--1010--Tempter of the Bone【DFS+剪枝】
Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He原创 2013-07-12 15:24:25 · 496 阅读 · 0 评论 -
HDOJ--4323--Magic Number【编辑距离】
Problem DescriptionThere are many magic numbers whose lengths are less than 10. Given some queries, each contains a single number, if the Levenshtein distance (see below) between the number in the原创 2013-07-16 21:49:58 · 679 阅读 · 0 评论 -
HDOJ--1003--Max Sum【最大子段和】
Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5原创 2013-07-23 15:58:38 · 598 阅读 · 0 评论 -
HDOJ--1075--What Are You Talking About【字典树】
Problem DescriptionIgnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it lea原创 2013-10-20 02:28:38 · 874 阅读 · 0 评论 -
HDOJ--3037--Saving Beans【数论】
题意:把不多于m个豆子存在n棵树上。豆子取到m,把多余的豆子存在第n+1棵树上,就转换成了把m个豆子存在n+1棵树上的排列组合问题,答案为C(n+m,m)Lucas定理:A、B是非负整数,p是质数。AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0]。则组合数C(A,B)与C(a[n],b[n])*C(a[n-1],b[n-1])*..原创 2013-12-02 22:56:14 · 665 阅读 · 0 评论 -
HDU--3829--Cat VS Dog【最大点独立集】
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3829题意:动物园有n条狗,m头猫,p个小孩,每个小孩有一个喜欢的动物和讨厌的动物,现在动物园要转移一些动物,如果一个小孩喜欢的动物在,不喜欢的动物不在,他就会happy,问动物最多能使几个小孩happy。思路:一个比较明显的二分图,不能以猫狗为顶点,那样找到的是哪些动物会转移,以小孩为顶点原创 2014-10-18 20:40:48 · 919 阅读 · 0 评论