06 2016 档案

摘要:kmp。 字符串的题都好难啊。 进行一次kmp,用一个dp[i]数组记录前缀中前缀匹配后缀的数量(算本身) 同时进行一个类似kmp的过程,用变量k表示满足长度限制后,最长的匹配前缀和后缀。 则num[i]=dp[k]。为什么呢? 首先变量k满足了长度限制,dp数组记录了匹配串的数量。dp多的1正好可以充当目前的前缀和后缀。 字符串的题都好难啊。。 #include #... 阅读全文
posted @ 2016-06-30 23:43 invoid 阅读(209) 评论(0) 推荐(0)
摘要:树链剖分。 这道题就写个dfs序,乱搞一下就过了。 简单型的树剖 #include #include #include using namespace std; const int maxn = 200000 + 10; const int maxm = 400000 + 10; int g[maxn],v[maxm],next[maxm],eid; int size[maxn],so... 阅读全文
posted @ 2016-06-30 18:13 invoid 阅读(398) 评论(0) 推荐(0)
摘要:树链剖分。 除去换根的俩个操作,在树链剖分后很容易实现。 换根以后只需操作的时候进行分类讨论即可。 操作2不会受到换根的影响。 操作3:如果询问点就是根,输出整个线段树最小值。 如果询问点在根到1的路径上,查询(1,st[p])和(ed[p]+1,n)的最小值,st和ed分别为出入栈的编号,p为路径上最靠近询问点的点。 其他情况下,输出范围(st[... 阅读全文
posted @ 2016-06-29 17:33 invoid 阅读(204) 评论(0) 推荐(0)
摘要:dfs序+线段树. 首先生成树的出栈入栈序。 然后入栈设为a[u],出栈设为-a[u]。 子树在线段树上是一个连续的范围,所以三个操作都可以在线段树上实现了。 ps:val设成int,wa了无数发。。 #include #include #include #include using namespace std; typedef long long LL; const int... 阅读全文
posted @ 2016-06-29 10:29 invoid 阅读(141) 评论(0) 推荐(0)
摘要:堆+huffman树。 huffman二叉树构造法就是每次把最小的俩个合并起来,构成一个树。 但k叉树每回减少(k-1)个,可能最后会有一个坑位被浪费掉,导致答案增加(用心去感受) 于是我果断回忆去年他们游记里面写到,多余的先合并下。。 然后1A了。。。 #include #include #include #include #include using namespace ... 阅读全文
posted @ 2016-06-28 08:54 invoid 阅读(210) 评论(0) 推荐(0)
摘要:最短路+最小割 首先如何使最短路变长?就是要每一条最短路都割一条边。 我们求出每个点到点1和点n的距离,就可以知道哪些边在最短路上(一开始没有想到求到0和n的距离,想用floyd,但是n=500,怕超时。) 第二步呢,我们把每条在最短路上的边加入一个新图,跑最小割就可以了(把所有最短路都割掉一条边,最短路就变长了,这个也没想到) #include #include #include... 阅读全文
posted @ 2016-06-27 19:55 invoid 阅读(211) 评论(0) 推荐(0)
摘要:拓扑排序+堆。 转自popoqqq神犇。 反向建图跑拓扑排序然后逆序输出。 为什么不能正的来呢,因为不知道选当前菜要先制作哪种菜。 逆序过来跑拓扑的话,也能保证满足限制条件编号小的在前面。 题外话:我都打完了才发现第三个样例输出不对,一看题直接就弃疗了。。事实证明就改动几个字母。。。。 toposort我一直喜欢叫”土拨”sort,可能是因为我口语不好吧。。。 #includ... 阅读全文
posted @ 2016-06-27 17:08 invoid 阅读(156) 评论(0) 推荐(0)
摘要:暴力。 O(n^6)暴力卡过,72ms。 莫名其妙做这道题时感觉十分烦躁,难受,只能这样了。 O(n^4)的方法是这样差分一下。判断的时候tmp=t[i][j],t[i][j]-=tmp,t[i+r][j]+=tmp,t[i][j+c]+=tmp,t[i+r][j+c]-=tmp,同时查看是否合法。 还有一个更优化的是如果r,c不行,r*q和c*q也不行。这个好像就是正解的办法? 为什么... 阅读全文
posted @ 2016-06-27 12:48 invoid 阅读(184) 评论(0) 推荐(0)
摘要:A*搜索。 A*搜索的基础百度百科(实在偷懒没看论文之类的),在这里不说了。 A*搜索很关键的是h(n)估价函数的选取(表示现在到结束节点需要的距离) 设d(n)为实际到结束节点的距离。h(n) #include #include using namespace std; const int dx[]={2,1,-1,-2,-2,-1,1,2},dy[]={1,2,2,1,-1,-2,-2... 阅读全文
posted @ 2016-06-26 11:46 invoid 阅读(199) 评论(0) 推荐(0)
摘要:数学。 x^2 % n = 1 则 (x+1)(x-1) = kn. 设 x+1 = k1*n1, x-1=k2*n2。 则 k1*k2=k , n1*n2=n。 算出每个大于sqrt(n)的约数,然后分别作n1,n2尝试是否可行。 算x一定要取模。否则1会变成n+1。 #include #include #include #include #include using names... 阅读全文
posted @ 2016-06-25 22:58 invoid 阅读(138) 评论(0) 推荐(0)
摘要:费用流。 传说中建模之集大成之题。。。 https://www.byvoid.com/blog/noi-2008-employee 题解 题解里面关于建模已经讲的很全了。 我根据自己的理解写写建模的实际意义。 如果a[i]-a[i-1]>=0,代表需要新雇佣人。否则就代表有人离开了。(离开并不一定要在t[i]+1天,如果后面人多余的话,很早就会离开)。 1.建模为S->i容量为 a[i... 阅读全文
posted @ 2016-06-25 13:50 invoid 阅读(162) 评论(0) 推荐(0)
摘要:水题。 按位处理,复杂度O(nlogm)。真心好看。。。。。 #include #include #include using namespace std; const int maxn = 100000 + 10; int n,m,k,l,f1,f2,res; char s[20]; int op[maxn],t[maxn]; inline int calc(int f,int i... 阅读全文
posted @ 2016-06-25 09:39 invoid 阅读(160) 评论(0) 推荐(0)
摘要:splay. 就是splay,没别的了。 #include #include #include using namespace std; const int maxn = 600000 + 10; const int inf = 0x3f3f3f3f; struct Splay { int v[maxn],s[maxn],sum[maxn]; int l[maxn],r... 阅读全文
posted @ 2016-06-25 09:07 invoid 阅读(166) 评论(0) 推荐(0)
摘要:状态压缩dp。 一道很好的dp题。 我们在选的时候并不知道它会对后面的选择造成什么影响,所以不能正向dp。 f[i][s]表示第i次选择后,选择的宝物二进制为s的期望得分。 初始状态均为0,答案为f[0][0]。 #include #include #include using namespace std; const int maxn = 20; const int maxm =... 阅读全文
posted @ 2016-06-25 08:59 invoid 阅读(142) 评论(0) 推荐(0)
摘要:dp。 如果状压dp的话,只能拿到50分。而正解既比状压好写,又是正解。。 f[i][j][k]表示第i行有j列有一个棋子,有k列有俩个棋子,然后dp转移一下就好了(方程太难写,不写了。。。) 100*100*mod可能爆int,所以用了long long。 阅读全文
posted @ 2016-06-23 19:18 invoid 阅读(169) 评论(0) 推荐(0)
摘要:更相减损数。 上手就debug了3个小时,直接给我看哭了。 3个函数都写错了是什么感受? 乘2函数要从前往后乘,这样后面的数乘2进位以后不会干扰前面的数。 除2函数要从后往前除,这样前面的数借来的位不会除2次。 然后函数里面俩个类里面的变量名不要打混。 哭瞎 #include #include #include using namespace std; const int ma... 阅读全文
posted @ 2016-06-23 18:27 invoid 阅读(186) 评论(0) 推荐(0)
摘要:费用流。 这道题的模型比较明显,拆点也是很容易看出来的。 #include #include #include using namespace std; const int maxn = 1000 + 10; const int maxm = 500000 + 10; const int inf = 0x3f3f3f3f; int g[maxn],v[maxm],f[maxm],c[ma... 阅读全文
posted @ 2016-06-23 15:44 invoid 阅读(156) 评论(0) 推荐(0)
摘要:莫名其妙的dfs算法。 1.这道题首先要推出来,如果有弓形或者环形,答案必须是环长度和弓形俩条路长度之差的约数。 而且如果你直接按照原图来建图你是跑不出来的。 1.如果你每个点访问一次时dfs所有点,tle。 2.如果你打vis标记,你判断不出来弓形,wa。 3.如果妄图用一个in数组记录哪个点in[u]=0,然后从这个点开始跑的话。整体做个环,甩出去个头支的。wa+奇奇怪怪的错误。 ... 阅读全文
posted @ 2016-06-23 08:29 invoid 阅读(249) 评论(0) 推荐(0)
摘要:dp. 用g[x][i]代表第x根柱子的i个原盘会到哪个柱子,f[x][i]代表所用步数。 则根据g[x][i-1]和g[g[x][i-1]][i-1]就能知道搬运的过程是怎样的。 #include #include #include using namespace std; char p[7][3]; int g[40][3],n; long long f[40][3]; ... 阅读全文
posted @ 2016-06-21 13:29 invoid 阅读(137) 评论(0) 推荐(0)
摘要:二分+dfs。 这道题求图的最小环的每条边的权值的平均值μ。 这个平均值是大有用处的,求它我们就不用记录这条环到底有几条边构成。 如果我们把这个图的所有边的权值减去μ,就会出现负环。 所以二分求解。 阅读全文
posted @ 2016-06-20 20:49 invoid 阅读(173) 评论(0) 推荐(0)
摘要:莫比乌斯函数。 完全平方数的倍数有如下特点。 1.首先不是质数的完全平方数可以忽略不计,因为它总是一个质数的完全平凡数的倍数。 2.每个质数i的完全平方数的倍数的个数为(n/(i*i))。 3.每对质数i,j的完全平方数的倍数已经在i和j时被重复统计了俩次,个数为(n/((i*j)^2))。 。。。 阅读全文
posted @ 2016-06-20 10:28 invoid 阅读(160) 评论(0) 推荐(0)
摘要:tarjan,状态压缩。 首先直接暴力可过。 第一步tarjan缩强联通分量,图变成一个dag。跑一个拓扑排序。 然后倒序用一个f[i]二进制数组表示i能到达的点。 因为2000个点已知数据类型放不下,用一个bitset。 然后答案就是sum(size[u]*size[v]) f[u][v]=1,u能到v。 #include #include #include #include ... 阅读全文
posted @ 2016-06-17 12:11 invoid 阅读(175) 评论(0) 推荐(0)
摘要:dp. 用到俩次dp,用1和0代表俩种颜色,首先对于每块木板我们进行一次dp,g[i][j]代表前j个格子刷i次最多能涂到几个格子。 则 g[i][j]=max(g[i-1][k],max(cnt[j]-cnt[k],j-k-cnt[j]+cnt[k])。 k #include #include using namespace std; const int maxn = 100 + 10; ... 阅读全文
posted @ 2016-06-17 10:57 invoid 阅读(242) 评论(0) 推荐(0)
摘要:矩阵乘法。 x[n] = {x[0],1} * ( {a,0} ^ n ) {b,1} 写成这样谁能看懂。。。。 noi里的大水题。我居然 都1A了。 阅读全文
posted @ 2016-06-16 20:26 invoid 阅读(132) 评论(0) 推荐(0)
摘要:二分图匹配。 每个点分为俩个点0和1,表示有床的人和要睡觉的人。跑最大流。 图中所有边的流量均为1 1.S向每个有床的人(0)连一条边。 2.每个不回家的人和校外的人(1)向T连一条边。 3.每个有床的人和自己连一条边(0->1)。 4.每个认识的人连一条边(0->1). 阅读全文
posted @ 2016-06-16 13:50 invoid 阅读(154) 评论(0) 推荐(0)
摘要:dp. f[i][j]表示放置第i个数有j个逆序对的方案数。 s[i][j]维护前缀和(f[i][0]~f[i][j])。 状态转移方程 f[i][j]=s[i-1][j]-s[i-1][max(j-1,0)]。 oi界十大水题。 #include #include #include using namespace std; const int mod = 10000; const ... 阅读全文
posted @ 2016-06-16 11:20 invoid 阅读(134) 评论(0) 推荐(0)
摘要:前缀和。 维护一下前缀和,枚举。 按道理复杂度在当时是过不去的吧。。 #include #include #include using namespace std; const int maxn = 5000 + 10; const int k = 5001; int s[maxn][maxn]; int n,r,res; int main() { memset(s,... 阅读全文
posted @ 2016-06-15 22:05 invoid 阅读(166) 评论(0) 推荐(0)
摘要:BSGS算法 给定y、z、p,计算满足yx mod p=z的最小非负整数x。p为质数(没法写数学公式,以下内容用心去感受吧) 设 x = i*m + j. 则 y^(j)≡z∗y^(-i*m)) (mod p) 则 y^(j)≡z∗ine(y^(i*m)) (mod p)(逆元) 由费马小定理y^( 阅读全文
posted @ 2016-06-15 20:50 invoid 阅读(772) 评论(1) 推荐(0)
摘要:凸包,(旋转卡壳)。 首先要求的4个点肯定在凸包上,所以先求一个凸包。 然后枚举第一个点,和它的对角线。然后另外俩个点分别与它们构成一个三角形 根据凸多边形的性质,三角形的移动方向是单调的,所以这样枚举的复杂度为O(n^2)。 #include #include #include #include #define eps 1e-6 using namespace std; const... 阅读全文
posted @ 2016-06-15 13:30 invoid 阅读(270) 评论(0) 推荐(0)
摘要:树状数组,离线处理。 首先把询问按左端点的大小升序排序。 从左往右扫描的过程中,将一个颜色第一次出现的位置变为0,第二次出现的位置变为1. #include #include #include using namespace std; const int maxn = 1000000 + 10; struct Query { int l,r,id; }q[maxn]; st... 阅读全文
posted @ 2016-06-14 20:10 invoid 阅读(185) 评论(0) 推荐(0)
摘要:凸包,floyd求最小环。 首先第三个变量是可以由变量1,2得到的,所以可以省去。 然后如果产品在由原材料构成的凸包里,它就是可以被合成的。 所以问题就是要求包含所有产品的最小的凸包。 所以所有取到的边都在确定的一侧,所以先判断出哪些边可以取,跑floyd最小环就可以了。 #include #include #include #include #define eps 1e-10 u... 阅读全文
posted @ 2016-06-14 18:07 invoid 阅读(161) 评论(0) 推荐(0)
摘要:线段树维护联通性。 题目下方有分析。 题解里面说的行数等于题目中的行数-1. 经过分析一共(r1,c1)->(r2,c2)一共有四种方式。 假设r1=1,r2=0。 1.直接过去。 2.先到(0,c1)再过去。 3.先到(1,c2)再过去。 4.先到(0,c1)再到(1,c2)再过去。 用一个数组a 阅读全文
posted @ 2016-06-14 15:19 invoid 阅读(1239) 评论(1) 推荐(0)
摘要:费用流。 建图比较重要。 1.S->id[0][0] flow=k。 表示k条路径。 2.S->id[i][0] flow=1, 每次消耗1流量就补充1流量。 3.id[i][1]->T flow=1, 保证每个点都经过一次。 4.id[i][0]->id[j][1] 存在一条路。 这样建图每个点都会被经过一次,而且都是从编号小的点转移过来,满足题目条件。 #include #... 阅读全文
posted @ 2016-06-13 21:43 invoid 阅读(136) 评论(0) 推荐(0)
摘要:求导。 大水题。。。 写这个题的目的就是要强调一些细节。 printf输出%时要用2个%。 如果S>a*b的话,直接输出0,如果太小,直接输出100。 求导就不说了// 最关键的地方一笔带过?我连一笔都不带! #include #include #include #include using namespace std; const int maxn = 100000 + 10; ... 阅读全文
posted @ 2016-06-13 18:58 invoid 阅读(80) 评论(0) 推荐(0)
摘要:组合数,对数。 这道题要用到20w的组合数,如果直接相乘的话,会丢失很多精度,所以用去对数的方式实现。 注意指数,因为取完一次后,还要再取一次才能发现取完,所以是(n+1)次方。 double 会爆掉,需要用long double 然后就是scanf和printf读入输出long doube会发生不可逆转的错误(dev-cpp),所以可以读入输出时候强制转换类型,或者用cin,cout(后... 阅读全文
posted @ 2016-06-12 22:21 invoid 阅读(200) 评论(0) 推荐(0)
摘要:数学期望。 过每条河的时间的可能在[L/v,3*L/v]间均匀分布,数学期望为2*L/v。 然后在加上在陆上走的时间。 #include #include #include using namespace std; int n,d,p,L,v,kase; double res; int main() { while(scanf("%d%d",&n,&d)==2 && d) ... 阅读全文
posted @ 2016-06-12 08:08 invoid 阅读(101) 评论(0) 推荐(0)
摘要:递推。 用f[n][l][r]表示n个柱子,从左面能看到l个,从右面能看到r个。 如果我们按照从小到大的顺序放置的话,放置最高的柱子后,大量状态都能递推到当前状态,很难写出递推式。 但是我们如果从小到大放置的话,高度为1的柱子放进去只会产生3种不同的情况。 1.最左面.2.中间。3.右面 在中间的哪里是无所谓的。 所以f[i][j][k]=f[i-1][j-1][k]+f[i-1][j... 阅读全文
posted @ 2016-06-11 23:46 invoid 阅读(130) 评论(0) 推荐(0)
摘要:递推,组合。 考虑第一名有i个人,则f[n]=sum(C(n,i)*f[n-i]),递推即可.. #include #include #include using namespace std; const int mod = 10056; const int maxn = 1000 + 10; int n=1000,T; int C[maxn][maxn]; int f[maxn]; ... 阅读全文
posted @ 2016-06-11 23:10 invoid 阅读(114) 评论(0) 推荐(0)
摘要:递推。 用f[i]代表i个盒子的放法,设g[i]=2^n-f[i],代表i个盒子不满足条件的放法。 枚举第一个U所在的位置j。则方法有g[j-2]*(2^(i-j-2))种,j-1必须是L。 所以就慢慢递推了。。。 #include #include #include using namespace std; const int maxn = 100 + 10; int... 阅读全文
posted @ 2016-06-11 22:53 invoid 阅读(135) 评论(0) 推荐(0)
摘要:状态压缩,记忆化搜索。 用一个5进制数来表示每堆排到了哪一个位置。和2进制是一样的,不过不能用位运算。 #include #include #include using namespace std; const int maxn = 2000000+10; double dp[maxn]; bool vis[maxn]; char s[10][10][5]; int v,v2; do... 阅读全文
posted @ 2016-06-11 22:48 invoid 阅读(165) 评论(0) 推荐(0)
摘要:枚举,条件概率。 2^20次方等于100w,是大约可以没准还能过的。 二进制枚举时,如果买东西的人恰好为r个,设概率为p,就将sum[i]+=p(sum[i]为r个人买东西时第i个人买东西的概率),tot+=p(tot为r个人买东西的概率) 要求的就是sum[i]/tot。 P(第i个人实际买东西)=P(r个人买东西且第i个人在其中)/P(r个人买东西)。 r为0时特判 #inc... 阅读全文
posted @ 2016-06-11 16:11 invoid 阅读(116) 评论(0) 推荐(0)
摘要:解码,暴力。 恬不知耻地把暴力题解放了上来,因为k比较小,直接暴力找到字符串第k大就可以了。 编码解码就是根据组合数学公式算出来它到底在哪。 dfs返回bool就能使得找到字典序第k大字符串以后退出dfs,节省时间。 #include #include #include using namespace std; const int maxl = 30; char s[3][maxl... 阅读全文
posted @ 2016-06-11 13:28 invoid 阅读(142) 评论(0) 推荐(0)
摘要:筛法。 首先使cnt[i]=sqr(n/i),这样cnt[i]就表示gcd(x,y)大于等于i的数对的个数,然后倒序枚举减去gcd大于i的个数就可以得到ans[i]。最终得到ans[1]。 这个算法单次复杂度是O(n)的,和欧拉函数线性筛一样,不过更好写。 但是T=600,欧拉函数只需要计算一次,每次输出就可以了,所以在T很大的情况下还是欧拉函数更好。 反正水题。。。 #inclu... 阅读全文
posted @ 2016-06-11 10:54 invoid 阅读(141) 评论(0) 推荐(0)
摘要:唯一分解定理。 可以看出在最后每个a的系数是杨辉三角的第n行。 但是不能递推,否则会tle。 就从C(n-1,0)开始乘n-k再除以k。记录下每个的系数,如果该项系数小于m就代表和答案有关。 代码里的ok为true时,代表和答案有关。 #include #include #include #include using namespace std; const int maxn = ... 阅读全文
posted @ 2016-06-10 23:51 invoid 阅读(168) 评论(0) 推荐(0)
摘要:二分图最小权完美匹配。 一个最小费用流就能跑了,记住检查一下,容量是否跑满,如果没有跑满,就说明没有完美匹配。 #include #include #include using namespace std; const int maxn = 500+10; const int maxm = 50000 + 10; const int inf = 0x3f3f3f3f; int g[ma... 阅读全文
posted @ 2016-06-10 20:35 invoid 阅读(139) 评论(0) 推荐(0)
摘要:dp. 首先我们可以看到每个时间段只能往一个方向转移最多t步(t为时间段的长度),所以我们可以按时间段dp。因为这个前后值互不影响,也不用占用这一维空间就可以省去。 然后每个时间段内是一列一列(行) 进行递推。 如果朴素枚举是O(n^2)时间无法承受。所以每列(行)用一个单调队列维护dp,队首放着移动距离最大可以到达的点,这样复杂度就降到了O(n)。每次要递推n列(行)。所以总复杂度为O(k*... 阅读全文
posted @ 2016-06-10 18:47 invoid 阅读(737) 评论(0) 推荐(2)
摘要:筛法,打表。 通过打表可知,但gcd(a,b)==a xor b时,a xor b = a-b. 就是求满足 c = a-b且c = a xor b 的c的个数。 #include #include #include using namespace std; const int maxn = 30000000; int ans[maxn+10]; int a,b,c,n; int T... 阅读全文
posted @ 2016-06-10 15:47 invoid 阅读(103) 评论(0) 推荐(0)
摘要:唯一分解定理。 挨个记录下每个质数的指数。 #include #include #include #include using namespace std; const int maxn = 100000 + 10; typedef long long LL; double ans; int p,q,s,t; bool mark[maxn]; int prime[maxn],cnt; ... 阅读全文
posted @ 2016-06-10 13:17 invoid 阅读(150) 评论(0) 推荐(0)
摘要:快速幂, 循环节,斐波那契数列 只是一个水水的题目,可以看出循环节是小于n^2的,所以先枚举出循环节。然后快速幂取模就可以了。 但要注意必须用unsigned long long,而且我用scanf读入还出现了意想不到的问题,所以只能用cin读入。 这是一个很大的坑点. #include #include #include using namespace std; const int... 阅读全文
posted @ 2016-06-10 10:31 invoid 阅读(129) 评论(0) 推荐(0)
摘要:扩展欧几里得。 枚举a,根据x1,x3和递推式可得。 (a+1)*b-k*mod=f[3]-a*a*b. 通过扩展欧几里得求出b. 带入原式进行计算。 #include #include #include using namespace std; const int maxn = 20000 + 10; const int mod = 10001; typedef long lo... 阅读全文
posted @ 2016-06-10 09:55 invoid 阅读(135) 评论(0) 推荐(0)
摘要:费用流。 裸的拆点最小费用流,一跑就行。 核弹预警,为何wa20多发。build函数一定要返回true。。。。。。 太可怕了 #include #include #include #include using namespace std; const int maxn = 5000 + 10 ; const int maxm = 200000 + 10; const int inf ... 阅读全文
posted @ 2016-06-10 08:52 invoid 阅读(122) 评论(0) 推荐(0)
摘要:lca。 3个点分别lca,可以知道,深度最深的lca就是答案。 #include #include #include using namespace std; const int maxn = 500000 + 10; const int maxm = 1000000 + 10; const int maxl = 22; int g[maxn],v[maxm],next[maxm],... 阅读全文
posted @ 2016-06-08 23:49 invoid 阅读(210) 评论(0) 推荐(0)
摘要:状压dp。 #include #include #include using namespace std; const int maxn = 12; int f[1<<maxn][1010],cnt[maxn],fac[maxn]; char s[maxn]; int T,d,N,n; int main() { fac[0]=1; for(int i=1;i<=10;i... 阅读全文
posted @ 2016-06-08 19:23 invoid 阅读(130) 评论(0) 推荐(0)
摘要:最小费用最大流。 这道题的特点在于每个修车的人所需要等待的时间要加上之前这个技术人员维修车的时间。 直观地我们可以每个技术人员建造n个点,费用分别为k*t(k=1,2,3…)(t为维修时间)。 但是这样很可能会超时,我们又发现,因为总共只有n个人来修车,我们每次用过每个修车人员后,再临时增加点,就可以避免浪费。 决策时,就变成了这个技术人员倒数第几个修这个车。 语言比较混乱,但这道题是好... 阅读全文
posted @ 2016-06-08 18:03 invoid 阅读(168) 评论(0) 推荐(0)
摘要:网络流 首先算出每行每列的数的和。 每行的值减去c,每列的值减去R 然后每行和每列之间连边,容量为19. 这样一来,(i,j)的流量相当于(i,j)的值-1. 这样就避免了流量为0不对应答案的尴尬情况。 #include #include #include using namespace std; const int maxn = 1000 + 10; const int max... 阅读全文
posted @ 2016-06-08 09:40 invoid 阅读(189) 评论(0) 推荐(0)
摘要:最大流。 流可以对应一种分配方式。 显然最大流就可以表示最多匹配数 #include #include #include using namespace std; const int maxn = 500 + 10; const int maxm = 100000 + 10; const int maxl = 30; const int inf = 0x3f3f3f3f; char ... 阅读全文
posted @ 2016-06-08 09:32 invoid 阅读(143) 评论(0) 推荐(0)
摘要:斜率优化dp。 不想写表达式。。。。 s[i]维护前缀p,sx[i]维护前缀p*x。 这样将原dp转移方程转化为了 f[i]=f[j]+(s[i-1]-s[j])x[i]-(sx[i-1]-sx[j])+c[i]。 斜率优化,当i决策时,j>k且j优于k则 x[i]>(f[j]-f[k]+sx[j]-sx[k])/(s[j]-s[k]). 这样就要维护一个下凸包。 #inclu... 阅读全文
posted @ 2016-06-02 14:40 invoid 阅读(142) 评论(0) 推荐(0)
摘要:莫队算法+树状数组+离散化。 一定要注意莫队转移时增加或减少的逆序对数,比较容易写挂。 离散化那部分虽然效率很低,但是很好写,正确性也很容易保证,虽然会拖慢程序运行速度,但编码的复杂度却大大降低了。 我觉得是一种不错的选择。//反正是抄的黄学长的。。 #include #include #include #include using namespace std; const int ... 阅读全文
posted @ 2016-06-01 19:47 invoid 阅读(146) 评论(0) 推荐(0)
摘要:莫队算法。 说白了就是乱搞。。。。。 这道题必须离线。 正解是树状数组,首先计算每个颜色第一个点构成的序列的答案。(每个颜色只有一个点,直接维护前缀和就可以了)。 然后询问按左端点排序,每回扫到一个点x,就在x的颜色的下一点的位置上+1。 这样俩个前缀和相减时,当且仅当(我一直觉得这四个字很newbee)区间里有某种颜色,答案+1。当然很多种颜色就很多个+1. 我直接莫队乱搞。第一次都... 阅读全文
posted @ 2016-06-01 16:12 invoid 阅读(200) 评论(0) 推荐(0)