上一页 1 2 3 4 5 6 7 8 9 10 ··· 16 下一页
摘要: 题目大意就是说两个人掷飞镖,飞镖在所给定的图形内就记一分,现在给定N个图形(圆、三角形和矩形),问每一次比赛(没人分别掷三次)谁赢。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #i... 阅读全文
posted @ 2014-05-09 20:59 再见~雨泉 阅读(469) 评论(0) 推荐(0) 编辑
摘要: 题目大意:你和朋友两人玩游戏,将一个图片均等切割成W* H块,打乱每一小块的位置。拼图游戏开始。每次,可以交换任意两块,记下交换的次数,图片还原游戏结束。得分为执行交换的次数。得分越小越好。现在,给你W和H, 还有你朋友的得分S,问,你能够得到小于S分的概率。解题思路:首先,在考虑问题时,只和块数有... 阅读全文
posted @ 2014-05-09 20:52 再见~雨泉 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 这个比最长回文子串就多了一个条件,就是回文字串(这里相当于人的高度)由两端向中间递增。才刚刚看了看manacher,在用模板A了一道题后,还没有完全理解manacher,然后就准备把这道题也直接带模板的。却发现这个递增的要求实在是麻烦,然后实在是没办法了,就把manacher算法拆开了,写两遍,按照子串的中间是一个数还是两个数来写。其他的什么地方都没改,只是扩展的时候把题目要求的条件加上就好了。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #i... 阅读全文
posted @ 2014-03-25 13:14 再见~雨泉 阅读(495) 评论(0) 推荐(0) 编辑
摘要: 题目大意就是说在给定的字符串里找出一个长度最大的回文子串。才开始接触到manacher,不过这个算法的确很强大,这里转载了一篇有关manacher算法的讲解,可以去看看:地址神器: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 using namespace std;15 #define INF 0x3f3f3f3f16 #de... 阅读全文
posted @ 2014-03-25 12:59 再见~雨泉 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 原网址:http://blog.sina.com.cn/s/blog_70811e1a01014esn.htmlmanacher算法是我在网上无意中找到的,主要是用来求某个字符串的最长回文子串.不过网上的版本还不太成熟,我就修改了下.不要被manacher这个名字吓倒了,其实manacher算法很简单,也很容易理解,程序短,时间复杂度为O(n).求最长回文子串这个问题,我听说有个分治+拓展kmp的算法,不过我估计后缀数组也可以.但杀鸡岂能用牛刀?现在进入正题:首先,在字符串s中,用rad[i]表示第i个字符的回文半径,即rad[i]尽可能大,且满足:s[i-rad[i],i-1]=s[i+1, 阅读全文
posted @ 2014-03-25 12:56 再见~雨泉 阅读(429) 评论(0) 推荐(0) 编辑
摘要: 开始做字符串专题,地址第一题水题,暴力就可以做 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 using namespace std;15 #define INF 0x3f3f3f3f16 #define inf (-((LL)1 T CMP_MIN(T a, T b) { return a T CMP_MAX(T a, T ... 阅读全文
posted @ 2014-03-25 12:50 再见~雨泉 阅读(128) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1007直接见代码吧。不过这个是N*logN*logN的尽管如此,我怎么感觉我的比他们的还快??? 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 using namespace std; 15 #define INF ... 阅读全文
posted @ 2014-03-09 20:18 再见~雨泉 阅读(1954) 评论(1) 推荐(0) 编辑
摘要: Problem F: Frequent valuesYou are given a sequence ofnintegersa1, a2, ... , anin non-decreasing order. In addition to that, you are given several queries consisting of indicesiandj(1 ≤ i ≤ j ≤ n). For each query, determine the most frequent value among the integersai, ... , aj.Input SpecificationThe 阅读全文
posted @ 2014-03-06 15:43 再见~雨泉 阅读(1431) 评论(0) 推荐(0) 编辑
摘要: N(3N20000)ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If two players want to compete, they must choose a referee among other ping pong players and hold th 阅读全文
posted @ 2014-03-06 15:28 再见~雨泉 阅读(1229) 评论(0) 推荐(0) 编辑
摘要: K Smallest SumsYou're given k arrays, each array has k integers. There are kkways to pick exactly one element in each array and calculate the sum of the integers. Your task is to find the k smallest sums among them.InputThere will be several test cases. The first line of each case contains an in 阅读全文
posted @ 2014-03-05 22:15 再见~雨泉 阅读(949) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3253经典题目了,大意是说如果要切断一个长度为a的木条需要花费代价a, 问要切出要求的n个木条所需的最小代价。无论是以下哪种方法,最原始的思路就是从相反的角度思考,将每两个合并,花费的代价是他们两个的和,一直到最后只剩下一个方法一:使用STL的priority_queue,先将所有的木条放入到队列中。每次取出两个木条将他们的长度相加,加入到花费当中去,然后放回到队列中。这样计算的时间复杂度就是O(NlogN)。方法二:使用单调队列,我们可以分析到,由于每次取出的都是优先队列中最小的两个,也就是首部的两个,那我们可以考虑另外借用一个数组b用来 阅读全文
posted @ 2014-03-01 22:00 再见~雨泉 阅读(393) 评论(0) 推荐(0) 编辑
摘要: 经典的字典树的题目了,这次完全是按照自己的风格来写的,没有参考其他人的代码风格来写。分析:如果采用常规的暴力枚举,那么复杂度就是O(n*n*str.length) = O(10^9),这明显是会超时的 采用字典树的方式的话所有的字符串的每一个字符都只会被访问一次,所以复杂度就是O(n*str.length) = O(10^5) 这个复杂度也很好分析:由于每一个字符串的长度不会超过10,那么当建一颗字典树时,那它的高度就不会超过10,就算最后没有一个会产生矛盾的号码,那么也只有n(10^4)个叶子节点 1 #include 2 #include 3 #include 4 #in... 阅读全文
posted @ 2014-03-01 21:24 再见~雨泉 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 地址http://acm.hdu.edu.cn/showproblem.php?pid=1896题目大一比较简单,就是说在一条直线道路上有n个石头,往前走,遇到一个数一个,如果遇到的是第奇数个那就把这个石头往前扔距离D[i], 如果是第偶数个,就放置不管。问遇到的最后一个石头距离出发点的位置是多少。做起来也比较简单就是每遇到第奇数个石头,就将其加上D[i],放回到优先队列(priority_queue)中,然后再去掉一个石头直接看代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #incl... 阅读全文
posted @ 2014-03-01 21:09 再见~雨泉 阅读(850) 评论(0) 推荐(0) 编辑
摘要: 题目地址http://poj.org/problem?id=3468题目大意很简单,有两个操作,一个Q a, b 查询区间[a, b]的和C a, b, c让区间[a, b] 的每一个数+c第一次线段树的延时标记,花了好大的功夫才写好==!很容易看出来使用使用线段树记录区间的和,但是难点在于每次修改的是一个区间而不是一个点所以采用的方法就是每次做修改操作时,只将区间[a,b]的标记+c,而不是真正意义上的将区间[a, b] 的每一个值+c。而当我们做查询操作时,就只需要将区间[a, b]在从[1, N]开始查找到查找到时所经过的区间的标记往下传递就可以了(同时记得更新当前节点的值) 1 #in 阅读全文
posted @ 2014-02-28 17:20 再见~雨泉 阅读(204) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3535分组背包,每一组加了以下三个限制 0 stands for the sets that should choose at least 1 job to do, 1 for the sets that should choose at most 1 , 2 for the one you can choose freely#include #include #include #include #include #include #incl... 阅读全文
posted @ 2013-12-01 01:00 再见~雨泉 阅读(265) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 16 下一页