其他算法
文章平均质量分 79
余浩媛
AC是种恶习,但是我似乎已经戒不掉了!
展开
-
hdu 3415 Max Sum of Max-K-sub-sequence(单调队列)
题意:由n'个数组成的环形序列a1,a2...an,其中a1左边是an,an右边是a1,,求该序列中长度不超过k的子序列的最大和。思路:将a1..an复制到a1+n...a2*n,然后用sum[i]记录前i项和,那么sum[i]-sum[i-m]就是长度为m的子序列的和,用单调队列维护下标,具体过程如下。代码:/* * main.cpp * * Created原创 2015-11-12 22:10:57 · 312 阅读 · 0 评论 -
最大子序列和分治算法
#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include//#define ONLINE_JUDGE#define eps 1e-8#define INF 0x7fffffff原创 2015-10-05 14:55:32 · 756 阅读 · 0 评论 -
string和stringstream用法总结
一、stringstring 是 C++ 提供的字串型態,和 C 的字串相比,除了有不限长度的优点外,还有其他许多方便的功能。要使用 string, 必須先加入这一行:#include 接下來要宣告一个字串变量,可以写成:string s;我们也可以在宣告的同时让它设成某个字串:string s="TCGS";而要取得其中某一個字元,和传统C 的字串转载 2015-12-04 14:26:33 · 319 阅读 · 0 评论 -
hdu 1878 欧拉回路(水题,判断欧拉回路)
判断一个图中是否存在欧拉回路(每条边恰好只走一次,并能回到出发点的路径),在以下三种情况中有三种不同的算法:一、无向图每个顶点的度数都是偶数,则存在欧拉回路。二、有向图(所有边都是单向的)每个节顶点的入度都等于出度,则存在欧拉回路。以上两种情况都很好理解。其原理就是每个顶点都要能进去多少次就能出来多少次。三、混合图(有的边是单向的,有的边是无向的。常被用于比喻城市里的交通网原创 2015-12-10 10:41:11 · 343 阅读 · 0 评论 -
hdu 1207 汉诺塔II
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1207多柱汉诺塔最优算法设计探究:http://www.cnblogs.com/fanzhidongyzby/archive/2012/07/28/2613173.html这题是一个四柱汉诺塔问题,基于J. S. Frame算法,具体参考上述链接。Frame算法的递归原创 2015-12-13 16:32:33 · 352 阅读 · 0 评论 -
hdu 1716 排列2(水题)
排列2Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6084 Accepted Submission(s): 2332Problem DescriptionRay又对数字的列产生了兴趣:现原创 2015-12-10 20:13:52 · 355 阅读 · 0 评论 -
Cleaning Shifts POJ - 2376(区间覆盖,排序+贪心)
Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into原创 2015-10-28 23:10:39 · 655 阅读 · 0 评论 -
hdu 1556 Color the ball(前缀和)
Color the ball /* * mai.cpp * * Created on: 2015年9月15日 * Author: chen */#include#include#include#include#include#include#include#include#include#include#include#include原创 2015-11-09 17:56:25 · 414 阅读 · 0 评论