
acm
文章平均质量分 64
Kblacksmith
守恒
展开
-
图论基础
(以前的草稿,内容很少,删了也可惜,LCA、桥、割、联通分量、二分图之类的都没写了,因为懒。。。)一.图的遍历:1.前向星名字虽然很奇怪,其实就是链表存储的图,当矩阵存不下或者花费时间较多的情况下使用。(基本没用过矩阵建图了。。。。)也可以使用stl的vector,但是一般比较占内存和效率不够。贴上代码:#include #include #include usi原创 2017-07-24 16:52:28 · 423 阅读 · 0 评论 -
hdu 5878 I Count Two Three 丑数 二分
I Count Two ThreeTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 649 Accepted Submission(s): 332Problem DescriptionI will sho原创 2016-09-19 21:07:57 · 439 阅读 · 0 评论 -
hdu 5893 List wants to travel 树链剖分求区间段数
用到树链剖分和线段树合并,线段数存储段数即需要包含左端点颜色右端点颜色和段数和,但是难点在树上的查询的时候会牵扯到 不同链之间的交接处是否重色,参考了别人的写法但是代码写的还是冗余度很高,好累,先放着吧,看以后有没有时间来精简下。#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <s原创 2016-09-22 17:19:42 · 798 阅读 · 0 评论 -
hdu 5900 QSC and Master 区间dp(2016 ACM/ICPC Asia Regional Shenyang Online)
QSC and MasterTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 495 Accepted Submission(s): 161Problem Description Every school has some le原创 2016-09-19 12:51:38 · 478 阅读 · 2 评论 -
hdu 5889 最短路最小割 2016 qingdao regional online
求出原图的所有最短路的边加入网络流中,再求一遍最大流即为答案。#include<bits/stdc++.h>using namespace std;const int maxn = 1005;#define inf 1e9#define INF 1e9const int maxm = 4000000+50;struct Node{ int v,w; Node(int v原创 2016-09-18 11:45:36 · 312 阅读 · 0 评论 -
单调队列 例子:hdu3401 trade(dp加单调队列)
单调队列指的是指队列中的元素是单调的。如:{a1,a2,a3,a4……an}满足a1<=a2<=a3……<=an,a序列便是单调递增序列。同理递减队列也是存在的。单调队列出现的机会不多,而且最常和dp一起出现。单调队列是一种工具而不是解题的方法。 单调队列的出现可以简化问题,队首元素便是最大(小)值,这样,选取最大(小)值的复杂度便为o(1),由于队列的性质,每个元素入队一次,出队一次,维护队列原创 2016-09-05 19:29:31 · 1331 阅读 · 0 评论 -
hdu 3518 Boring counting 后缀数组
Boring countingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2873 Accepted Submission(s): 1185Problem Description 035 now faced a tough p原创 2016-08-13 15:12:32 · 380 阅读 · 0 评论 -
hdu 1403 Longest Common Substring 后缀数组求最长公共子串
Longest Common Substring Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5823 Accepted Submission(s): 2063Problem Description Given two st原创 2016-08-13 11:36:52 · 391 阅读 · 0 评论 -
hdu 1403 Longest Common Substring 后缀数组求最长公共子串
Longest Common SubstringTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5823 Accepted Submission(s): 2063Problem DescriptionG原创 2016-08-13 11:31:14 · 491 阅读 · 0 评论 -
hdu 5556 Land of Farms(最大独立集)
这题很明显可以用最大独立集来做,但是写代码很麻烦,是本人目前碰到的建图最麻烦的一道题原创 2016-04-12 20:56:36 · 916 阅读 · 0 评论 -
poj 1568 (α-β剪枝优化搜索)
Find the Winning Move Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description 4x4 tic-tac-toe is played on a board with four rows (numbered 0 to 3 from top to bottom)原创 2016-09-01 16:10:55 · 1020 阅读 · 0 评论 -
hdu 5879 Cure 打表
CureTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1137 Accepted Submission(s): 380Problem DescriptionGiven an integer n,原创 2016-09-19 21:15:23 · 358 阅读 · 0 评论 -
hdu 5880 Family View ac自动机屏蔽文章关键词 2016青岛网赛
Family View Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 906 Accepted Submission(s): 171Problem Description Steam is a digital distribu原创 2016-09-20 21:32:02 · 811 阅读 · 0 评论 -
hdu 5927 Auxiliary Set dfs
Auxiliary SetTime Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 318 Accepted Submission(s): 93Problem DescriptionGiven a rooted原创 2016-10-06 22:41:07 · 497 阅读 · 2 评论 -
hdu 5929 Basic Data Structure 双端队列
Basic Data StructureTime Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 260 Accepted Submission(s): 62Problem DescriptionMr. Frog原创 2016-10-06 22:32:25 · 1236 阅读 · 2 评论 -
hdu 5918 Sequence I kmp
Sequence ITime Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 470 Accepted Submission(s): 184Problem DescriptionMr. Frog has two原创 2016-10-05 23:02:44 · 385 阅读 · 0 评论 -
hdu 5920 Ugly Problem 贪心构造 大整数
Ugly ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 347 Accepted Submission(s): 131Special JudgeProblem DescriptionEv原创 2016-10-05 20:36:20 · 893 阅读 · 0 评论 -
poj 3162 walking race 树形dp 求符合条件区间
题意:一棵树,求出从每个结点出发能到走的最长距离(每个结点最多只能经过一次),将这些距离按排成一个数组得到d[1],d[2],d[3]……d[n] ,在数列的d中求一个最长的区间,使得区间中的最大值与最小值的差不超过m。这题正解应该是树的直径加单调队列(可以点这看单调队列),因为只用保存最大值最小值。但是觉得onlign的也能过,所以用了直径加rmq,但是时间是可以但是爆内存。。尴尬。。。原创 2016-10-01 12:19:13 · 463 阅读 · 0 评论 -
hdu 5887 herb gathering 搜索剪枝
参考了队友的玄学剪枝。其实这样剪枝就能过我也是忐忑的。。。。#include #include #include using namespace std;typedef long long ll;struct node{ long long int v,h;};bool cmp(node a,node b){ if(a.h==b.h)原创 2016-09-29 20:14:42 · 417 阅读 · 0 评论 -
树状数组单点更新和区间更新,二维数组poj2155(区间更新,单点查询)(已加入区间修改区间查询)
1)、单点增减+区间求和思路:C[x]表示该点的元素:sum(x)=C[1]+C[2]+……C[x][cpp] view plain copy print?int arr[MAXN]; inline int sum(int x){int res=0;while(x)res+=arr[x],x-=lowbit(x);return res;}转载 2016-09-13 20:03:14 · 1075 阅读 · 0 评论 -
hihoCoder 1387 A Research on "The Hundred Family Surnames" 2016 ICPC 北京网络赛E题
#1387 : A Research on "The Hundred Family Surnames"时间限制:3000ms单点时限:3000ms内存限制:256MB描述The Hundred Family Surnames is a classic Chinese text composed of common Chinese surn原创 2016-09-25 15:48:28 · 1142 阅读 · 0 评论 -
hdu 2448 Mining Station on the Sea km算法+最短路
Mining Station on the SeaTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3081 Accepted Submission(s): 932Problem DescriptionT原创 2016-10-10 18:45:43 · 535 阅读 · 0 评论 -
hdu 5876 Sparse Graph(补图最短路) 2016 ACM/ICPC Asia Regional Dalian Online 1009
Sparse GraphTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 183 Accepted Submission(s): 68Problem DescriptionIn graph theor原创 2016-09-10 21:04:50 · 875 阅读 · 0 评论 -
hdu5877 Weak Pair 线段树 (2016 icpc dalian online 1010)
Weak PairTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 597 Accepted Submission(s): 207Problem DescriptionYou are given a原创 2016-09-11 13:00:58 · 663 阅读 · 0 评论 -
hdu 1520 简单树形dp
G - Anniversary party Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 1520 Description There is going to be a party to celebrate the 80-th Anniv原创 2016-08-04 15:09:33 · 801 阅读 · 0 评论 -
hdu 4570 Multi-bit Trie
原文链接 。。。这一题,,,花时间最多的是看题目。题意(别处复制): 一个长度为n的数列,将其分成若干段(每一段的长度要<=20), 要求∑ai*(2^bi)最小,其中ai是每一段数列的第一项,bi是每一段的长度。 比如sample imput n=7,A={1 2 4 4 5 4 3},将其分成1 2 4| 4 5| 4| 3, 则其所用空间为1*2^3+4*2^2+4*2^1+3*原创 2016-08-03 19:56:58 · 537 阅读 · 2 评论 -
KK's Steel bestcoder round 71 hdu 5620(裴波那契)
Problem Description Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right)N(1≤N≤10 18 ) meters steel,he will cut it into steels as many as possible,and原创 2016-02-16 12:57:57 · 427 阅读 · 0 评论 -
poj 3258 River Hopscotch
DescriptionEvery year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight ri原创 2016-01-05 10:41:15 · 242 阅读 · 0 评论 -
hdu3669 水题
Meteor Shower这道明明是水题但我却在数据上跪了好多次。。。。。好蛋疼 纯纯的带标记BFS#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;int g[310][310];int dir[5][2]={{0,0},{1,0},{-1,0},{0,1原创 2016-01-04 17:10:44 · 328 阅读 · 0 评论 -
类包装的优先队列 小顶堆实现
最近实习时比较了一下链表实现的优先队列和用堆实现的优先队列时间的差距。。发现数据大了后差的真是超多。。 数据量到了100000后前者需要25秒左右的时间,而后者只需0.03秒左右。(当然与机房实习时的机子烂也有关系)#include <iostream>#include <algorithm>using namespace std;template<class T>class Vector原创 2016-01-04 09:42:30 · 609 阅读 · 0 评论 -
hdu 1281 棋盘游戏 二分图最大匹配
行,列分别看成点,然后最大匹配,最基础的二分匹配。#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int n,m,k;const int maxn = 105;int bmap[maxn][maxn];int bmask[maxn];int n原创 2016-01-04 09:33:20 · 429 阅读 · 0 评论 -
poj2449 Remmarguts' Date
这题题意为给一张有向图,还有起点s,终点e,求s到e的第k短的路。思路:此题要用到A*算法,先求反向的从终点e到各个点的最短路径,定义结构体struct node{ int p,h,g; bool operator <(const node a)const { return g+h<a.g+a.h; }}即p为该点,h为从原点走到p的已花费代价,g为预估到终点的花费,即p到终原创 2015-11-01 15:08:38 · 422 阅读 · 0 评论 -
HOLEDOX MOVING (POJ1324)
在这里我们将蛇的状态描述为如下三元组(x,y,sta),其中 (x,y)是蛇头的坐标,state 记录的是身体的状态,由于身体最长为七段,每一段相对于前一段只有上下左右四种状态,仅需要两位表示,则身体所有块的状态最多需要 7×2=14 位二进制数表示,则我们可以构建矩阵vis[x][y][sta] 来保存访问过的状态,以避免重复访问相同的状态,后面的工作就是传统的广搜过程了; 代码很容易看得懂#i原创 2015-10-31 00:41:02 · 375 阅读 · 0 评论 -
区间dp一般模板
区间dp一般由小区间推出大的区间:#include #include #include #include using namespace std;int dp[1010][1010];int main(){for(int i=0;i dp[i][i]=........ for(int len=1;len区间长度 {原创 2015-08-04 09:03:34 · 1732 阅读 · 0 评论 -
hdu 1251 入门trie树
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 33555 Accepted Submission(s): 12730Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写原创 2016-08-04 16:37:04 · 267 阅读 · 0 评论 -
hdu 4616 Game (树形dp)
GameTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2007 Accepted Submission(s): 649Problem Description Nowadays, there are more and more原创 2016-08-05 17:47:15 · 436 阅读 · 0 评论 -
2016 ACM/ICPC Asia Regional Dalian Online 1006 football game 1007 hdu 5873 hdu 5874
Football GamesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3505 Accepted Submission(s): 655Problem DescriptionA mysterious原创 2016-09-10 21:16:38 · 477 阅读 · 0 评论 -
poj 1729 Jack and Jill (比较有特色的bfs)
Description Ever since the incident on the hill, Jack and Jill dislike each other and wish to remain as distant as possible. Jack and Jill must attend school each day; Jack attends a boys’ school whil原创 2016-08-30 22:53:05 · 2306 阅读 · 0 评论 -
hdu2874 Connections between cities
H - Connections between cities Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 2874 Description After World War X, a lot of cities have been ser原创 2016-08-09 10:30:41 · 481 阅读 · 2 评论 -
2016 ACM/ICPC Asia Regional Dalian Online 1008 Function
FunctionTime Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1427 Accepted Submission(s): 126Problem DescriptionThe shorter, the原创 2016-09-10 22:02:11 · 641 阅读 · 0 评论