自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(12)
  • 收藏
  • 关注

原创 hdu 5908 哈希

题目链接:点击打开链接 题意:问把一段区间分成相同数个数相同几份。   分析:直接枚举约数,然后判断两个区间相不相等,这里可以考虑区间哈希(数据比较水 , 所以愉快的水过去了23333) 详情见代码: #include using namespace std; const int maxn = 1e5 + 20; typedef unsigned long long ul; int A[m

2016-11-12 14:28:56 451

原创 uvalive 4015 树形背包dp

题意:给你一颗n个节点的树,求从根节点出发最多走x远,问最多能经过多少个节点。 分析:考虑dp方程dp[i][j][0]表示以i为根节点、经过j个节点、不回到i、最小要走多远, dp[i][j][1]表示以i为根节点、经过j个节点、回到i、最小要走多远。 容易想到状态转移方程 dp[u][j][0] = min(dp[u][j][0],dp[u][j-k][1] + dp[v][k][0]

2016-09-05 11:39:25 330

原创 codeforces 374D 树状数组或者线段树

题意:给你n个操作,1,0,分别为在字符串上加上1,0。-1为删除再位置上ai的字符。 分析:单点更新。考虑树状数组,不过这个题目和一般的不同,需要二分,而线段树本身在更新和查询操作的时候就是相当于二分。所以线段树更容易理解。 具体详见代码: 线段树 #include #define lson l ,mid ,rt<<1 #define rson mid+1,r,rt<<1|1 usin

2016-08-20 14:38:28 416

原创 codeforces 703D 树状数组 + 离线处理 + 离散化

题意:给你m个操作,每个操作求区间[l,r]中偶数个元素的异或值。 分析:根据异或的性质,偶数个的异或为0,所以我们考虑再一次元素本身,因此,偶数变成奇数,奇数变成偶数。 具体详见代码:#include using namespace std; const int maxn = 1e6 +20; struct node { int l,r,id; bool operator < (const

2016-08-20 14:33:32 409

原创 hdu 5862 树状数组 + 扫描线 + 离散化

题意:给你n条线段 ,求有多少个交点。 分析:第一直觉就是扫描线,然后发现要用树状数组维护前缀和。因为坐标大但是点数小,所以考虑离散化。 具体详见代码#include #include #include #include typedef long long ll; using namespace std; const int maxn = 2e5 +20; ll BIT[maxn],X[max

2016-08-18 19:51:52 738

原创 codeforces 706D trie树 或 muliset

题意:插入,删除,询问三个操作。 分析:显然trie树都支持这三个操作,但是代码比较长,用muliset更短小精悍。但是两者的本质都是一样,都是找与二进制不同的,尽量凑成全是1. muliset #include using namespace std; multiset dp; bool check(int a,int b) { auto it = dp.lower_bound(a);

2016-08-13 17:09:34 543

原创 poj1177 线段树 + 扫描线

题意:给出一些矩形,求其轮廓的周长。 分析:不断的向线段树中添加边。 具体的实现详见代码#include #include #include #include #define lson l , mid , rt<<1 #define rson mid + 1, r , rt <<1 | 1 using namespace std; const int maxn = 5e3 +20; cons

2016-08-12 19:23:27 339

原创 codeforces 706C 简单dp

题意:给你一些字符串,然后要把这些字符串变成字典序 分析:因为决策只会有前面的字符影响,并且具有最优子结构(自己想想) 具体实现详见代码。#include using namespace std; const long long INF = 3e18; const int maxn = 1e5 + 20; long long B[maxn] , dp[maxn][2]; vector A;

2016-08-12 19:15:57 589

原创 poj 3667 线段树区间合并

题意:有很多房间,每次客人来住的时间要连续的房间,多次操作查询。 分析:维护prefix和suffix数组来表示一段区间连续的个数 具体实现详见代码:#include #include #include #include #define lson l , mid , rt << 1 #define rson mid + 1, r, rt << 1 | 1 using namespac

2016-08-12 19:11:19 383

原创 poj2777 线段树

题意:给一些线段区间染色,然后问你一段区间的不同颜色的个数 分析:因为颜色比较小 可以压缩为二进制表示 细节详见代码#include #include #include #include using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 const int maxn = 1e5 + 20; st

2016-08-12 19:08:28 281

原创 poj 1195 二维树状数组(单点更新)

题意:在一个矩阵中做一些add和query操作   。  二维树状数组裸题 矩阵sum(x1,y1,x2,y2) = sum(0,0,x2,y2) - sum(0,0,x1-1,y2, ) - sum(0,0,x2,y1-1) + sum(x1-1,y1-1);  #include #include #include #include #define lson l,mid,rt

2016-08-12 19:00:25 355

原创 poj1177 线段树 + 扫描线

题意:给你一些矩形,求其周长。 分析:通过扫描线,每次扫描到进去线段就现在线段树上加上这段线段,如果是出去的就删除就可以了。 分两次统计分别统计长和宽。 具体实现详见代码。 #include #include #include #include #define lson l , mid , rt<<1 #define rson mid + 1, r , rt <<1 | 1 using na

2016-08-12 18:46:55 363

空空如也

空空如也

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

TA关注的人

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