自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

不慌不忙、不急不躁

https://github.com/JeraKrs

  • 博客(109)
  • 收藏
  • 关注

原创 hdu 5478 Can you find it(数论)

题目链接:hdu 5478 Can you find it解题思路将人头按照高低排序,从低的优先考虑。用线段树维护空位,每次考虑前后空ki个人之后可以站的位置,优先向前站。代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll pow_mod (ll

2015-09-30 16:41:41 842

原创 hdu 5477 A Sweet Journey(水)

题目链接:hdu 5477 A Sweet Journey代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5 + 5;int N, A, B, L;int main () { int cas; scanf("%d", &cas);

2015-09-30 16:39:12 691

原创 hdu 5475 An easy problem(线段树)

题目链接:hdu 5475 An easy problem解题思路单点修改。貌似直接暴力都可以过,数据很弱。代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1e5 + 5;#define lson(x) ((x)<<1)#define rson(x)

2015-09-30 16:30:58 884

原创 hdu 5471 Count the Grid(容斥)

题目链接:hdu 5471 Count the Grid解题思路比赛的时候想太复杂了,因为n只有10,直接搞个容斥就可以解决了。 首先将矩形切割成若干不相交的小矩形,即同一小矩形中的点状态一致,然后判断每个小矩形中v的最大值能是多少,接着考虑单一v值的情况下,用容斥求出答案。复杂度为o(1024*1024)代码#include <cstdio>#include <cstring>#includ

2015-09-30 16:27:58 1301

原创 hdu 5469 Antonidas(暴力剪枝)

题目链接:hdu 5469 Antonidas解题思路这题是水过的,极端数据下单组数据要跑接近8s。 思路是类似bfs的搜索,剪枝为如果移动方向向下,并且深度不够时不转移。代码#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <algorithm>using namespace std;

2015-09-30 16:21:17 1146

原创 hdu 5468 Puzzled Elena(前缀性质+dfs序+容斥)

题目链接:hdu 5468 Puzzled Elena解题思路预处理出每个数的因子(注意只需要质因子幂数最大为1的数,例如6=21∗316=2^1 * 3^1)然后用一个数组维护,fac[i]表示说当前有fac[i]个数包含i这个因子。然后dfs遍历这棵树,第一次遍历到节点u时,通过fac数组计算出现在有多少个数与W[u]不互质,待遍历完u的子树后,再计算一次,两个相减即为u子树中与W[u]不互质的

2015-09-30 16:17:50 875

原创 hdu 5462 Manors(半平面交)

题目链接:hdu 5462 Manors解题思路对于一个点(x,y)和两对科学家夫妇i,j而言 Ii=IjI_i = I_j ∑k=1m((x−xi)2+(y−yi)2)=∑k=1m((x−xj)2+(y−yj)2)\sum_{k=1}^{m} ((x-x_i)^2 + (y-y_i)^2) = \sum_{k=1}^{m} ((x-x_j)^2 + (y-y_j)^2) 将式子展开,得 ∑

2015-09-29 21:10:31 1333 2

原创 hdu 5461 Largest Point(水)

题目链接:hdu 5461 Largest Point解题思路暴力维护at2at^2和btbt的最大值和次大值。代码#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;typedef long long ll;const ll inf = 0x3f3f3f3f

2015-09-29 20:57:54 632

原创 hdu 5459 Jesus Is Here(dp)

题目链接:hdu 5459 Jesus Is Here解题思路其实每个c都对应这一个cff,并且串i由串i-1和i-2生成的,所以答案肯定也可以通过i-1,i-2获得。对于每个串,维护四个值dis(每个c的位置和),len(串的长度),cnt(多少个c),sum(答案) 具体转移公式见代码。代码#include <cstdio>#include <cstring>#include <algor

2015-09-29 20:50:13 627

原创 hdu 5458 Stability(树链剖分+强连通缩点+线段树)

题目链接:hdu 5458 Stability解题思路先将操作处理一遍,获得最终图,然后对图进行双联通缩点,剩下的肯定是一棵树,然后将操作逆着做一遍,遇到删边等于是加一条边,加的这条边u,v等于是将两节点路径上的点联通起来变成一个新的双联通分量,在同一个双联通分量中,明显ans=0。所以我们用线段树维护树的每条边权,一开始全为1,每次添加一条边,就将这条路径上的边权值置为0。代码#include <

2015-09-29 20:45:48 944

原创 hdu 5456 Matches Puzzle Game(记忆化搜索)

题目链接:hdu 5456 Matches Puzzle Game解题思路式子可以变换成A=B+C,从低位处理到高位,dp[i][j][b][c]dp[i][j][b][c]表示到第i位,j有没进位,b为数字B是否已经到达最高为,c为数字C是否已经到达最高位。代码#include <cstdio>#include <cstring>#include <algorithm>using namesp

2015-09-29 20:34:24 1466

原创 hdu 5455 Fang Fang(水题)

题目链接:hdu 5455 Fang Fang解题思路处理出每个c的位置,如果有相邻两个c的距离小于2即为-1代码#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 1e6 + 5;char s[maxn];int solve

2015-09-29 20:30:01 590

原创 hdu 5454 Excited Database(线段树)

题目链接:hdu 5454 Excited Database解题思路维护两科线段树,一棵i+j,一棵i-j。因为对角线上的值一定都是相同的,只是查询时的个数不一样,但是根据区间范围可以计算出来每条对角线的个数。每个树维护单一节点权值和s,从右边递增的和r,从左边递增的和l。查询的时候将矩形分成3份。代码#include <cstdio>#include <cstring>#include <al

2015-09-29 20:26:22 993

原创 hdu 5452 Minimum Cut(树链剖分)

题目链接:hdu 5452 Minimum Cut解题思路因为有一条一定要在给定的树上,所以我们可以求出切某条树边时,最少还需要再切割几条边可以使得该树边联通的两个点集不联通。先对给定的树做树链剖分,然后对剩余的非树边u,v,更新路径u-v上边的权值,加1。代码//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cs

2015-09-29 20:19:16 899

原创 hdu 5451 Best Solver(矩阵乘法+数论)

题目链接:hdu 5451 Best Solver解题思路因为取模的数很小,所以暴力找打循环节,然后求解。代码#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <set>#include <algorithm>using namespace std;const int maxn = 4

2015-09-29 20:14:58 970

原创 hdu 5445 Food Problem(多重背包)

题目链接: hdu 5445 Food Problem解题思路先对甜点做一次背包,容量表示能量值,对于每个能量值维护最小需要的体积,在对车做一次背包,容量表示花费,对于每个花费值维护最大可以提供的体积。多种背包的优化可以去看一下背包9讲。代码#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using

2015-09-29 17:46:44 737

原创 hdu 5447 Good Numbers(数论)

题目链接:hdu 5447 Good Numbers解题思路对于数K而言,good number的个数即为K的各个质因子的幂数累乘。但是题目给定数比较大1e24,肯定有有大于1e6的质因子,但是最多有三个。题目中又定条件,说第一大的质因子相同,第二大的一定不同,那么我们先将1e6以内的质因子分解,如果剩下的部分大于1e6的话,我们就需要再作判断,求两数的gcd,就可以将第一第二大的质因子分离,判断是

2015-09-29 17:36:07 1851

原创 hdu 5448 Marisa’s Cake(几何+凸包)

题目链接:hdu 5448 Marisa’s Cake解题思路这题和zoj 3871 Convex Hull有点像,不过点数比较大,不能接受o(n2)o(n^2)的算法。但是题目给定的是一个凸包,所以可以通过化简,在o(n)o(n)的复杂度内计算出答案。首先,对于一个三角形ABC SABC=fA×fB+fB×fC+fC×fA(fi表示点i和原点组成的向量)S_{ABC} = f_A \times

2015-09-29 16:49:55 949

原创 hdu 5449 Robot Dog(期望+lca)

hdu 5449 Robot Dog(期望+lca)题目链接:hdu 5449 Robot Dog解题思路n有50000,询问次数有100,每次询问的路径点数最多有100,对于不同询问去做动态规划,开一个dp[u][i]dp[u][i]表示在第u个节点匹配了i个的期望,显然最坏情况下dp数组的每个状态都要遍历到,复杂度为o(nqp)o(nqp),不能接受。换个想法,如果我们能知道从节点i走到节点j的

2015-09-29 16:09:34 1417

原创 uva 1459 - Flowers Placement(二分图匹配+暴力)

题目链接:uva 1459 - Flowers Placement暴力,在暴力的基础上用二分图匹配剪枝,如果当前位置放k,导致后面的位置不能匹配,即可回溯。#include #include #include #include using namespace std;const int maxn = 205;int N, M, K, cnt, L[maxn]

2015-09-23 22:40:22 682

原创 uva 1411 - Ants(几何+完美匹配)

题目连接:uva 1411 - Ants以两点间距离做权值,建图,做完美匹配。如果两线段AB与CD向交,那么AD或者BC边的权值小于AB和CD。#include #include #include #include using namespace std;const int maxn = 105;const double eps = 1e-9;struct

2015-09-23 22:34:58 1264

原创 uva 1349 - Optimal Bus Route Design(完美匹配)

题目链接:uva 1349 - Optimal Bus Route Design权值变为负的即便为求最小值。#include #include #include #include using namespace std;const int maxn = 105;const int inf = 0x3f3f3f3f;int N, L[maxn], Lx[ma

2015-09-23 22:27:45 822

原创 uva 1327 - King's Quest(强联通)

题目链接:uva 1327 - King's Quest建图,然后求强联通分量,与王子处在同一个联通分量的公主即为可选。#include #include #include #include #include using namespace std;const int maxn = 4005;int N, pre[maxn], sccno[maxn], d

2015-09-23 22:24:28 737

原创 uva 12168 - Cat vs. Dog(二分图匹配)

题目链接:uva 12168 - Cat vs. Dog类似uva 12083#include #include #include #include #include using namespace std;const int maxn = 505;typedef pair pii;int N, M, K, L[maxn];bool T[maxn];

2015-09-23 22:20:02 783

原创 uva 12083 - Guardian of Decency(二分图匹配)

题目链接:uva 12083 - Guardian of Decency对于男女可以分成X和Y,矛盾的两个人之间建立一条边, 做二分图最大匹配,每条被选取的边表示只能有一人被选中。#include #include #include #include #include #include #include using namespace std;const

2015-09-23 22:17:01 809

原创 uva 1201 - Taxi Cab Scheme(二分图匹配)

题目链接:uva 1201 - Taxi Cab Scheme建图,X和Y集合均为N个点,如果接完第i个人之后来得及接j,那么从Xi建一条边道Yj。做最大匹配,如果选中Xi到Yj这条边,说明i和j用的是同一辆车,那么需要几辆车即为没有边连入的Y集合点数个数,即为N-最大匹配数。#include #include #include #include #include

2015-09-23 22:11:38 661

原创 uva 1175 - Ladies' Choice(稳定婚姻问题)

题目链接:uva 1175 - Ladies' Choice稳定婚姻问题裸题。#include #include #include #include using namespace std;const int maxn = 1005;int N, pref[maxn][maxn], order[maxn][maxn], jump[maxn];int fut

2015-09-23 22:06:05 892

原创 uva 11419 - SAM I AM(最小覆盖)

题目链接:uva 11419 - SAM I AM行列匹配,对于每个点,所在的行列建一条边,做最大匹配,所选中的边数即为需要的炮数,最后在构造一下输出答案。#include #include #include #include #include using namespace std;const int maxn = 1005;const int inf =

2015-09-23 22:04:04 959

原创 uva 11383 - Golden Tiger Claw(完美匹配)

题目链接:uva 11383 - Golden Tiger Claw#include #include #include #include using namespace std;const int maxn = 505;const int inf = 0x3f3f3f3f;int N, L[maxn];int Lx[maxn], Ly[maxn], W[maxn]

2015-09-23 21:58:37 1027

原创 uva 10615 - Rooks(完美匹配)

题目链接:uva 10615 - Rooks显而易见,需要用到颜色种类即为行列中棋子个数的最大值k。问题是如何构造,建图,行和列去匹配,每次匹配一种颜色,将匹配到的边删除即可。需要注意的是,每次需要删除k条边,所以对于度数不足的点需要用无效边凑数,这样保证最后答案可以构造出来。#include #include #include #include using na

2015-09-23 21:55:45 1438

原创 uva 1045 - The Great Wall Game(二分图匹配)

题目链接:uva 1045 - The Great Wall Game枚举最终移动到的行和列,以及两条对角线,建立二分图,X集合为棋子,Y集合为目标位置,边权为棋子移动到目标位置的代价,做完美匹配,求最小值。#include #include #include #include #include using namespace std;const int ma

2015-09-23 21:50:32 1292

原创 uva 1006 - Fixed Partition Memory Management(完美匹配)

题目链接:uva 1006 - Fixed Partition Memory Management以任务为X,Y为每个处理器在倒数第几个完成,任务xi连向yj的边权值即为任务xi对处理器的时间贡献值,用KM算法求解。#include #include #include #include using namespace std;const int maxn = 5

2015-09-23 21:47:34 989

原创 hdu 5446 Unknown Treasure(lucas+中国剩余定理)

题目链接:hdu 5446 Unknown Treasurelucas+中国剩余定理裸题,注意在中国剩余定理里面,有可能两数相乘爆long long,要用按位乘的方式,但是这样的话exgcd返回值如果是负数就会出错,所以乘之前要取模成正的。#include #include #include using namespace std;typedef long lon

2015-09-13 21:59:57 1958

原创 hdu 5444 Elven Postman(二叉树)

题目链接:hdu 5444 Elven Postman其实就是一棵二叉搜索树,建完树遍历一下每个节点ans串就出来了。#include #include #include #include #include #include #include using namespace std;typedef long long ll;const int maxn

2015-09-13 21:56:47 864

原创 hdu 5443 The Water Problem(水)

题目链接:hdu 5443 The Water Problem怎么喜欢怎么来,两层for都可以,rmq,线段树。。。。#include #include #include using namespace std;const int maxn = 1005;int N, Q, A[maxn];int main () { int cas; scanf("%

2015-09-13 21:54:51 768

原创 hdu 5442 Favorite Donut(最小表示法+kmp)

题目链接:hdu 5442 Favorite Donut正序逆序分别做一遍最小表示法,但是因为逆序求出最小表示法下标对应的是为最大值,所以我们用kmp求出循环节长度,然后用下标取模即可。#include #include #include #include #include #include #include using namespace std;con

2015-09-13 21:52:59 887

原创 hdu 5441 Travel(生成树)

题目链接:hdu 5441 Travel类似与最小生成树的算法,将边和询问分别按照权值排序,每次枚举一个询问,将小于该询问的边全部链接,并且计算ans。#include #include #include #include using namespace std;typedef long long ll;const int maxn = 20005;con

2015-09-13 21:50:03 969

原创 hdu 5439 Aggregated Counting(规律)

题目链接:hdu 5439 Aggregated Counting1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 .... 按照每个数出现的次数1出现了1次,2,3出现两次,以此类推,将次数取出作为序列,会发现对应的序列仍是 1 2 2 3 3 4 4 4 5 5 5 ....即原序列。第一次last我们可以根据前缀和求出,但是对于第二次la

2015-09-13 21:47:29 984

原创 hdu 5438 Ponds(并查集+拓扑序)

题目链接:hdu 5438 Ponds先把点按照类似拓扑排序的方法删掉,然后对剩下的点用并查集维护,并且维护联通分量的点个数和权值和。#include #include #include #include #include using namespace std;typedef long long ll;const int maxn = 1e4 + 5;

2015-09-13 21:34:08 823

原创 hdu 5437 Alisha’s Party(优先队列)

题目链接:hdu 5437 Alisha’s Party按照先后顺序入队,按题意优先级大的先出队。#include #include #include #include using namespace std;const int maxn = 150005;const int maxm = 205;struct State { int w, id; S

2015-09-13 21:31:35 1123

空空如也

空空如也

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

TA关注的人

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