自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(33)
  • 问答 (1)
  • 收藏
  • 关注

原创 zoj3817 Chinese Knot 字符串哈希

对四个串的正反进行哈希,暴力枚举起点,dfs判是否可行。#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se second#define ll long lo

2015-08-30 18:17:23 360

原创 zoj3811 Untrusted Patrol bfs

一张无向图,有些点有摄像头,摄像头会记录下第一次经过这个点,现在给出一系列摄像头记录下的经过的点的次序,问依次经过这些点能不能遍历所有点。parse:从第一个点bfs,标记所有能访问的且没有摄像头的点,若第二个访问的点的邻居有已经被访问的,则可以在不经过其他有摄像头的点的情况下到达这个点,从这个点再bfs,访问过的点就无需再访问了,复杂度O(m)。#include#include#in

2015-08-29 23:21:09 367

原创 zoj3812 We Need Medicine 背包+位优化

We Need MedicineTime Limit: 10 Seconds      Memory Limit: 65536 KB      Special JudgeA terrible disease broke out! The disease was caused by a new type of virus, which will lead to lethal lymp

2015-08-27 00:14:02 433

原创 zoj3813 Alternating Sum 较难的线段树

Alternating SumTime Limit: 2 Seconds      Memory Limit: 65536 KBThere is a digit string S with infinite length. In addition, S is periodic and it can be formed by concatenating infinite repeti

2015-08-27 00:06:52 387

原创 hdu5145 NPY and girls 莫队算法,分块

莫队算法可以离线解决区间查询的问题,dp[i][j]可以O(1)得到dp[i+1][j]或dp[i][j+1],将l分为sqrt(l)块,按照块排序,再按照r排序,理论复杂度nsqrt(n);#include#include#include#include#include#include#include#include#include#include#include#in

2015-08-26 23:52:52 565

原创 hdu1890 Robotic Sort Splay树,区间反转,lazy标记

对spaly的一些理解:在Splay和Rotate两个操作对树中元素的大小关系是没有影响的,但会影响一些记录如sum值。这题就以id为key建树,区间反转用rev标记,标记下传时仅交换指向左右儿子的指针,反转后树中元素的大小关系发生了改变。删除根节点时将右子树中序遍历的第一个点(最小的点)伸展到根节点下,这样右子树的左子树为空。找第一个点时需要pushDown。#include#in

2015-08-24 17:21:11 449

原创 hdu5419 Victor and Toys 期望,差分前缀和

期望的分母是C(m,3),利用差分前缀和处理出每个点被多少区间覆盖,w[i]*C(sum[i],3)即为第i位的贡献。学习一下期望的求法考虑每个点的贡献。#include#include#include#include#include#include#include#include#include#include#include#include#include#d

2015-08-22 22:00:58 748

原创 hdu5107 K-short Problem 离线,离散化,线段树

题意:给出n栋楼的坐标和高度,询问parse:离线处理,对y坐标离散化,把楼和询问按x排序,每询问到x将#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se

2015-08-22 01:12:43 530

原创 hdu 5109 Alexandra and A*B Problem

枚举乘积长度,再枚举s串位置,再枚举s串前的大小,即可得出s串后的大小。学一下这种写法。#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se second#d

2015-08-21 23:32:20 298

原创 poj2828 Buy Tickets

题意:给出一系列插队序列,输出最终的队列、parse:从后往前处理,用线段树查询并更新第几个空位即可。#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se

2015-08-21 14:37:48 328

转载 树链剖分详解 模板

原文地址:树链剖分作者:starszys    “在一棵树上进行路径的修改、求极值、求和”乍一看只要线段树就能轻松解决,实际上,仅凭线段树是不能搞定它的。我们需要用到一种貌似高级的复杂算法——树链剖分。    树链,就是树上的路径。剖分,就是把路径分类为重链和轻链。    记siz[v]表示以v为根的子树的节点数,dep[v]表示v的深度(根深度为1),top[v]表示v所在的

2015-08-20 23:31:12 859

原创 poj3481 splayTree模板

#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se second#define pii pair#define inf (1<<30)#define eps

2015-08-20 22:26:50 445

原创 hdu3709 Balanced Number 数位dp

经过这道题对数位dp有了更深的理解。题意是求一个区间内有多少个平衡数,平衡数是这样定义的,以某一位数为支点,两边的数字乘力矩之和相等。For example, 4139 is a balanced number with pivot fixed at 3. The torqueses are 4*2 + 1*1 = 9 and 9*1 = 9, for left part and righ

2015-08-19 14:29:27 301

原创 hdu5103 RootedTree 状压dp,树形dp

这题说的是给了n(14)个点,每个点都以他 为根的最大可容的孩子个数和最小的可溶孩子个数L[i] ,R[i]问这n个点形成一棵树有多少种形态我们让 dp[i][S] 表示 一 i为根节点 的 拥有孩子S(二进制数)状态的 方案数 , sub[S] , 表示 以 S 状态表示的 森林的 方案数, sum[S] 表示 一S 状态的 有根树 的 方案数可以知道 dp[i]

2015-08-18 23:34:20 1052

原创 hdu5102 The K-th Distance bfs+结构体

题意:n个节点的一棵树,任意两节点间的距离是两点间路径的长度,因此有n*(n-1)/2个长度,求前k个的和。(2≤n≤100000,0≤K≤min(n(n−1)/2,106)分析:因为k不大,直接用bfs求出前k条路径就ok了,bfs的用法很好,用结构体记录节点,父节点,长度,找到k条后就退出,只需入队k次。这样每条路径都会算重复,因此k先乘2,结果在除2。#include#includ

2015-08-18 21:30:30 433

原创 hdu4933 Miaomiao's Function 数位dp+大数模板

Miaomiao's FunctionTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 228    Accepted Submission(s): 59Problem DescriptionFirstly ,

2015-08-17 16:57:47 445

原创 Codeforces Round #316 (Div. 2) E. Pig and Palindromes DP

500*500的矩阵,从(1,1)走到(n,m),求走出一条回文道路的方案数。要求回文从起点s和终点t若相同则可以走,并且走(n+m-2)/2步相遇,每一步的状态只与上一步有关,两个数组轮换记录状态即可。#include#include#include#include#include#include#include#include#include#include#inc

2015-08-16 01:16:25 560

原创 Codeforces Round #316 (Div. 2) D. Tree Requests dfs_clock,二分

将每一层的字符保存下来,并算出没个节点的时间戳,然后就可以二分查找了,当奇数个字符#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi first#define se second#defi

2015-08-16 01:07:03 349

原创 锯木厂选址 斜率dp优化

详细解释见点击打开链接#pragma comment(linker, "/STACK:1024000000,1024000000")#include#include#include#include#include#include#include#include#include#include#include#include#include#define fi fir

2015-08-14 17:26:30 408

原创 Codeforces Round #Pi (Div. 2) F. Mausoleum DP

点击打开链接题意:一系列数1,1,2,2,3,3,,,n,n,问形成1-k单调不减,k-n单调不增的排列数。另外有一些形如a>b,a=b,a分析:从1到n开始放置,或全放在首,或全放在尾,或放在首尾各一个,状态转移时判断是否可行。#pragma comment(linker, "/STACK:1024000000,1024000000")#include#include#incl

2015-08-12 19:42:36 511

原创 Codeforces Round #Pi (Div. 2) E. President and Roads 最短路,桥

题意:有n个城市,一些单向道路,每条道路会花费一些时间。总统从s到t,他会选择最快的道路,有一些道路是一定会选的,有一些道路通过修缮可以降低通过时间(>0),使总统必然走这条路,有些路一定是不通过的。分析:从s到t和从t到s分别跑出最短路,对最短路的边新建图,图中的桥即为必然要走的。#pragma comment(linker, "/STACK:1024000000,1024000000"

2015-08-12 11:08:55 653

转载 Manacher算法--O(n)回文子串算法

O(n)回文子串算法注:转载的这篇文章,我发现下面那个源代码有点bug。。。在下一篇博客中改正了。。     这里,我介绍一下O(n)回文串处理的一种方法。Manacher算法.原文地址:http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-lo

2015-08-12 09:33:31 326

原创 hdu5379 Mahjong tree 树形DP

题目本身并不难,就是解决起来有些繁琐。首先一个节点的非叶子节点若大于2则不存在,答案为0。否则讨论非叶子结点的数目0||1||2,同时也要考虑有没有叶子节点。有些子树的根节点可以选首尾,有些已经确定了,用flag来标识。#pragma comment(linker, "/STACK:1024000000,1024000000")#include#include#include#

2015-08-11 22:28:01 341

原创 hdu5064 Find Sequence 单调性dp

题意:给出一个数组a,之和为M,从中挑选出一些数组成数组b满足两个条件:(1) b1≤b2≤…≤bt (2) b2−b1≤b3−b2≤⋯≤bt−bt−1求最大的t。分析:a数组排序后,由于M#include#include#include#include#include#define pii pair#define inf (1ll<<60)#define l

2015-08-11 21:02:29 310

原创 hdu5352 MZL's City 网络流,最小费用最大流模板

MZL's CityTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 796    Accepted Submission(s): 285Problem DescriptionMZL is an active

2015-08-09 14:39:18 541

原创 hdu5362 Just A String DP

Problem Descriptionsoda has a random string of length n which is generated by the following algorithm: each of n characters of the string is equiprobably chosen from the alphabet of sizem.

2015-08-09 12:29:19 688

原创 hdu5361 In Touch 神奇的dij,神奇的写法

In TouchTime Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 784    Accepted Submission(s): 217Problem DescriptionThere are n soda

2015-08-08 11:42:56 639 3

原创 hud5358 数学,指针

题目:soda has an integer array a1,a2,…,an. Let S(i,j) be the sum of ai,ai+1,…,aj. Now soda wants to know the value below:∑i=1n∑j=in(⌊log2S(i,j)⌋+1)×(i+j)Note: In this problem, you can cons

2015-08-08 10:42:04 554

原创 hdu5057 分块法

题意:n个数,n每一块为256个数字,(i>>8)即为i所在的块。#include#include#include#include#include#define ll long longusing namespace std;const int maxn=100005;int n,m;int digit[maxn][10];int block[400][10][10];

2015-08-07 23:59:54 400

原创 codevs1285 宠物收养所 splayTree

删除节点时把它移到根节点,把它的后继移到根的右子节点,然后删除根。#include#include#include#include#include#define inf 1000000000using namespace std;const int maxn=200005;struct SplayTree{ int son[maxn][2],pre[maxn],val

2015-08-03 16:42:52 345

原创 codevs 1286 郁闷的出纳员 splayTree模板

#include#include#include#define inf 1000000000using namespace std;const int maxn=200005;struct SplayTree{ int son[maxn][2],pre[maxn],val[maxn]; int sum[maxn]; int rt,sz; void pu

2015-08-03 15:26:36 377

原创 营业额统计 splayTree

点击打开链接#include#include#include#include#define inf 1000000000using namespace std;const int maxn=100005;struct SplayTree{ int son[maxn][2],pre[maxn],val[maxn]; int rt,sz; void newN

2015-08-03 00:12:33 321

原创 uva5318 The Goddess Of The Moon dp+矩阵快速幂

dp[i][j]表示前i个以j结尾的方案数,可以由一系列dp[i-1][k]相加得出。类似求斐波那契数的第n项,由于非常大,用矩阵快速幂转移。import java.io.*;import java.math.BigDecimal;import java.util.ArrayList;import java.util.Arrays;import java.util.Comparator

2015-08-01 16:00:54 309

空空如也

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

TA关注的人

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