
ACM
文章平均质量分 83
Hugo5332
天地转,光阴迫
展开
-
一道单调栈的题目
一道单调栈的题目背景思路背景今天偶然遇到一道单调栈的题目,顺便复习下闲置已久的算法知识,题目的意思大致就是给你一个区间,找到子段和>=K的一个最小子段。思路子段问题的关键是前缀和,先求一下int sum[50005]={0};for(int i=0;i<len;i++) sum[i+1] = sum[i] + A[i];紧接着,关键就是维持一个单调栈,下面解释一下什么是单调栈,先给一段代码deque<int> dq; //双端队列数据结构for(int i=0;i原创 2020-12-10 13:34:20 · 272 阅读 · 0 评论 -
Dinic算法模板(自用)
#include <bits/stdc++.h>#define N 40005using namespace std;int const inf = 0x3f3f3f3f;int const MAX = 505; struct Edge{ int u,v,c; int next; }edge[N]; int cnt;//边数 int head[N...原创 2018-02-26 23:40:22 · 260 阅读 · 0 评论 -
Edmonds_Karp 算法模板(自用)
来自一篇写得很好的博客:http://blog.youkuaiyun.com/hsqlsd/article/details/7862903有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点,通常规定为1号点。另一个点也很特殊,只进不出,叫做汇点,通常规定为n号点。每条有向边上有两个量,容量和流量,从i到j的容量通常用c[I,j]表示,流量则通常是f[I,j]。通常可以把这些边想象成道路,流量就是这条道...原创 2018-02-26 10:01:35 · 341 阅读 · 0 评论 -
二分图匹配复习——匈牙利和KM算法
一,二分图最大匹配(匈牙利算法)基本思想:没有机会,就创造机会代码实现:#include<bits/stdc++.h>using namespace std;const int N=500;int mp[N][N];int match[N],vis[N];int k,m,n; //k是连接数 m是左边个数 n是右边个数 bool dfs(int x){ for(...原创 2018-02-26 00:13:19 · 366 阅读 · 0 评论 -
hdu5326 Work
HDU-5326 G.Work It’s an interesting experience to move from ICPC to work, end my college life and start a brand new journey in company. As is known to all, every stuff in a company has a title, ever...原创 2017-12-13 12:21:41 · 311 阅读 · 0 评论 -
hdu5319 Painter(模拟题)
C - Painter HDU - 5319 Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day, he got stuck in rut and the ideas dry up, he took out a drawing board and began to draw casuall...原创 2017-12-11 23:39:01 · 323 阅读 · 0 评论 -
哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)B 幸运大奖
题目描述tabris实在是太穷了,为了发财,tabris去买了一张彩票,幸运地中了特别奖。特别奖是这样的,不会直接给你发钱.会给你一串二进制数s,让你在s中选择一个不大于k的区间,这个区间表示的数就是获奖者的奖金数目.tabris中奖之后已经激动地蒙圈了,他不知道如何选择能获得最多的钱,你能帮帮他不?输入描述:输入一个整数T(T≤10),代表有T组数据.每组数据占两行.第一行有一个整数K(k≤...原创 2017-12-10 18:50:23 · 441 阅读 · 0 评论 -
哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)A 所有情况的和(思维题)
题目描述在acimo星球, tabris 是一名勇敢的屠龙勇士,在上绿岛屠龙前决定挑选N种装备武装自己,现在每种装备有两个,**但每种装备tabris必须选择拿一个**,**不能多也不能少**。每件装备有自己的属性值,能给tabris属性加成。对于不同种类的装备之间有叠加效果,如果选择多件装备,最终的属性加成为他们的乘积。若tabris初始属性值为0,最后属性加成的期望是多少。输入描述:有多组测试...原创 2017-12-10 18:47:44 · 378 阅读 · 0 评论 -
2017CCPC QinHuangDao M题
Safest BuildingsTime Limit: 1 Second Memory Limit: 65536 KBPUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for ...原创 2017-12-02 18:46:56 · 321 阅读 · 0 评论 -
2017 ACM/ICPC Asia Regional Shenyang Online E题
roblem DescriptionWe define a sequence F:⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2).Give you an integer k, if a positive number n can be expressed byn=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is...原创 2017-09-10 23:23:29 · 401 阅读 · 0 评论 -
ural1009(动态规划)
A - K-based NumbersURAL - 1009 Let’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example:101...原创 2017-07-18 23:00:14 · 371 阅读 · 0 评论 -
hdu1080(带权值最长上升子序列)
Human Gene FunctionsTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 5 Accepted Submission(s) : 3Font: Times New Roman | Verdana | GeorgiaFont Si...原创 2017-05-02 17:22:02 · 1280 阅读 · 0 评论 -
NYOJ42一笔画
一笔画问题时间限制:3000 ms | 内存限制:65535 KB难度:4描述zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。 输入第一行只有一个正整数N(N<=10)表示测试数据的组数。每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这个画...原创 2017-05-01 09:12:05 · 425 阅读 · 0 评论 -
Uva 11464 EvenParity
11464 - Even ParityTime limit: 3.000 secondsWe have a grid of size N x N. Each cell of the grid initially contains a zero(0) or a one(1). The parity of a cell is the number of 1s surrounding that cell...原创 2017-04-17 19:00:57 · 329 阅读 · 0 评论 -
hdu3088WORM BFS
WORMTime Limit: 20000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 278 Accepted Submission(s): 169Problem DescriptionPartychen discover a strange worm in E...原创 2017-04-12 08:52:47 · 283 阅读 · 0 评论 -
hdu3089(约瑟夫的优化)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3089题目大意:一共n人。从1号开始,每k个人T掉。问最后的人。n超大。解题思路:除去超大的n之外。就是个约瑟夫环的裸题。约瑟夫环递推公式,n为人数,k为步长。f(1)=0f(n)=[f(n-1)+k]%i i∈[2,n]f(n)还要经过起始位置修正,设起始位置为s,即ans=[f(n)+s]%n。...转载 2017-04-12 08:44:40 · 417 阅读 · 0 评论 -
FZU2150(Fire Game)(枚举+BFS)
I - Fire Game Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and t...原创 2017-04-10 20:48:18 · 593 阅读 · 0 评论 -
RMQ ST算法 uva11235(蓝书例题)
You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, det...原创 2017-04-09 01:13:11 · 291 阅读 · 0 评论 -
最小生成树总结
研究了一天最小生成树 ,衍生出来包括最小瓶颈树,次小生成树,最小树形图之类的算法,前两者基本能搞定,最后那个就。。不太懂了日后再回去看吧似乎很少用到,抄个模板以备不时之需 先谈谈最小瓶颈树 首先注意这两个定理:命题:无向图的最小生成树一定是瓶颈生成树。命题:瓶颈生成树不一定是最小生成树好了 知道这个之后无向图的瓶颈生成树就搞定了 贴上一道例题 :2429: [HAOI2006]聪明的猴子Time...原创 2017-04-08 23:05:34 · 449 阅读 · 0 评论 -
UVA11991(map+vector 离散化处理)
#include <iostream> #include<map> #include<vector> ...原创 2017-04-07 12:57:12 · 827 阅读 · 0 评论 -
poj1679(prim或者krusal的变形)
The Unique MSTTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 29778 Accepted: 10660DescriptionGiven a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (S...原创 2017-04-07 08:09:49 · 412 阅读 · 0 评论 -
Poj1847(floyd)
TramTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 15174 Accepted: 5586DescriptionTram network in Zagreb consists of a number of intersections and rails connecting some of them. In every in...原创 2017-04-06 23:45:24 · 250 阅读 · 0 评论 -
hdu4632(区间dp求字符串的回文子串数)
Palindrome subsequenceTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 3173 Accepted Submission(s): 1320Problem DescriptionIn mathematics, a ...原创 2017-04-01 23:48:28 · 636 阅读 · 0 评论 -
ZOJ1577(唯一分解定理)
ZOJ1577 GCD&LCMGiven x and y (2 <= x <= 100,000, 2 <= y <= 1,000,000), you are to count the number of p and q such that:1) p and q are positive integers;2) GCD(p, q) = x;3) LCM(p, q) ...原创 2017-03-30 23:49:45 · 457 阅读 · 0 评论 -
hdu2157(普通dp)
How many ways??Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3034 Accepted Submission(s): 1164Problem Description春天到了, HDU校园里开满了花, 姹紫嫣红, 非常...原创 2017-03-30 23:05:43 · 451 阅读 · 0 评论 -
LightOj 1031 区间dp
F - Easy Game LightOJ - 1031You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or m...原创 2017-03-29 23:58:24 · 348 阅读 · 0 评论 -
poj1061 好好理解拓展欧几里得
http://acm.pku.edu.cn/JudgeOnline/problem?id=1061Memory: 224K Time: 16MS解题思路题意: 略 思路: 根据题意,两个青蛙跳到同一个点上才算是遇到了,所以有 (x+m*t) - (y+n*t) = p * ll; (t是跳的次数,ll是a青蛙跳的圈数跟b青蛙的圈数之差。整个就是路程差等于纬度线周长的整数倍),转化一下...转载 2017-03-28 00:11:41 · 297 阅读 · 0 评论 -
最长子回文串与回文子串数
输入一个字符串,求出其中最长的回文子串。回文子串的含义是:正着看和倒着看是相同的,如abba和abbebba。 在这里我们采用的方法:第一步,倒转原子串;第二步,求两个串的最长公共子串;第三步,判断该子串是不是回文串。 代码如下:#include iostream#include stringusing namespace std;string longestPalSubstr(const s...原创 2017-03-26 21:30:26 · 468 阅读 · 0 评论 -
hdu2476(区间DP)
String painterTime Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4000 Accepted Submission(s): 1866Problem DescriptionThere are two strings A and...原创 2017-03-26 11:15:53 · 506 阅读 · 0 评论 -
poj2599
C - Brackets POJ - 2955We give the following inductive definition of a “regular brackets” sequence:the empty sequence is a regular brackets sequence,if s is a regular brackets sequence, then (s) and [...原创 2017-03-25 21:45:15 · 321 阅读 · 0 评论 -
LightOj1422(区间DP)
B - Halloween Costumes LightOJ - 1422 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, thes...原创 2017-03-25 20:16:09 · 803 阅读 · 0 评论 -
hdu1078(dp+dfs)
FatMouse and CheeseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9586 Accepted Submission(s): 4039Problem DescriptionFatMouse has stored so...原创 2017-03-25 15:31:34 · 958 阅读 · 0 评论 -
hdu1712(分组背包)
ACboy needs your helpTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6914 Accepted Submission(s): 3827Problem DescriptionACboy has N courses ...原创 2017-03-25 15:23:43 · 332 阅读 · 0 评论 -
状态压缩DP入门
原博地址:http://blog.youkuaiyun.com/u011077606/article/details/43487421 感谢分享状态压缩动态规划(简称状压dp)是另一类非常典型的动态规划,通常使用在NP问题的小规模求解中,虽然是指数级别的复杂度,但速度比搜索快,其思想非常值得借鉴。为了更好的理解状压dp,首先介绍位运算相关的知识。1.’&’符号,x&y,会将两个十进制数在二进...转载 2017-03-25 12:16:22 · 2129 阅读 · 0 评论 -
LightOj1282(阶乘前三位和后三位)
You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk.InputInput starts with an integer T (≤ 1000), denoting the number ...原创 2017-03-25 00:33:23 · 729 阅读 · 0 评论 -
多重背包的二进制优化
今天遇到一道多重背包超时了,所以才注意到这个优化方法 其思想大概如下,以下解释来源于网络,非我原创。(1)我们知道转化成01背包的基本思路就是判断我是取了你好呢还是不取你好。(2)我们知道任意一个实数可以由二进制数来表示,也就是2^0~2^k其中一项或几项的和。(3)这里多重背包问的就是每件物品取多少件可以获得最大价值。如果直接遍历转化为01背包问题,是每次都拿一个来问,取了好还是不取好,假如10...原创 2017-03-24 20:01:11 · 1618 阅读 · 0 评论 -
hdu2391(dp)
Filthy RichTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3177 Accepted Submission(s): 1420Problem DescriptionThey say that in Phrygia, the...原创 2017-03-23 21:00:00 · 245 阅读 · 0 评论 -
Poj3259(floyd)
POJ3259 - WormholesWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destinati...原创 2017-03-21 00:34:11 · 395 阅读 · 0 评论 -
最小生成树模版题
B - Networking You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may con...原创 2017-03-19 23:50:44 · 256 阅读 · 0 评论 -
poj3268(dijkstra算法变形)
D - Silver Cow Party One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidi...原创 2017-03-19 23:41:49 · 1580 阅读 · 0 评论