http://www.lydsy.com/JudgeOnline/problem.php?id=3315 果然自己太弱. 想不出dp方程啊.. 其实,以后记住...与上一个状态或下一个状态有关,,可以开一维或多维.. (这题暴力n^3都能a................. f(i, j)表示i个由j转移过来的最大价值 则 f(i, j)=max{f(j, k)}+p[i]  1<=k<j且x[i]-x[j]>=x[j]-x[k] f(i, j)=max{f(i, j), f(j, 0)…
http://www.lydsy.com/JudgeOnline/problem.php?id=3314 一眼就是维护一个距离为d的单调递减队列... 第一次写.....看了下别人的代码... 这一题只需要维护距离为d的最大,然后判断最大的是否大于等于自己高度*2 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream>…
http://www.lydsy.com/JudgeOnline/problem.php?id=3016 之前yy了一个贪心,,,但是错了,,就是枚举前后对应的字符(前面第i个和后面第i个)然后相同答案就+1,否则不操作.. QAQ 然后看了题解...神.. 首先序列肯定是偶数个,然后..一定有n/2个‘(’,和n/2个‘)’ 那么左边的一定都是‘(’,对于每一个‘(’,右边的一定有一个‘)’,所以我们想到差分,当右边多了‘)’,那么就要累计答案+1,维护一个sum,如果是‘(’就+1,‘)’就…
http://www.lydsy.com/JudgeOnline/problem.php?id=2017 这题太神了,我想了一个中午啊 原来是看错题一直没理解题解说的,一直以为题解是错的QAQ “开始玩游戏时,第一个玩家可以从堆顶拿走一枚或两枚硬币” 果然还是太弱 我们发现,每一个阶段都由上一个玩家决定的,即别人怎么拿限制了我怎么拿,那么 设状态为f(i, j)表示剩余i个硬币,上次拿了j个硬币,注意,是上一次! 则 f(i, j)=max{sum(1, i)-f(i-k, k)} 1<=k<…
http://www.lydsy.com/JudgeOnline/problem.php?id=2019 spfa裸题.....将飞机场的费用变成负,然后spfa找正环就行了 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue…
http://www.lydsy.com/JudgeOnline/problem.php?id=1600 说好的今天开始刷水.. 本题一开始我以为是排列组合,但是自己弱想不出来,只想到了如果四边有一条边大于或等于第三边,那么这个四边形构造不出来. 即 a>=b+c+d时,不存在四边形 那么存在的情况就是a<b+c+d 得到 a<a+b+c+d 因为a<2a,a<b+c+d 所以a<(a+b+c+d)/2=n/2 那么我们就可以dp了. 只要找所有满足的边满足比长度的一半…
题目 传送门:QWQ 分析 发现我们关心的不是棋子的位置,我们只关心棋子数量就ok. 首先每行每列最多两个棋子.这是显然的. 然后我觉得本题最难的部分就是对行进行讨论,蒟蒻我一直被限制在了对格点讨论.... $dp[i][j][k] $放了前$i$行,有$j$列有1个棋子,有$k$列有2个棋子.转移就很显然了. 代码 #include <bits/stdc++.h> typedef long long ll; ;; ll dp[maxn][maxn][maxn]; //dp[i][j][k]…
http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那么我们就可以枚举每一个比k大的放在最顶,其它的都放在下边即可. 还有,注意这是完全背包! #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <i…
http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!!! 本题裸的kdtree,比上一题还要简单...................................... 对于当前点,判断进入左或右子树,然后看答案是否能过分割线..如果能,进入右或左子树.........并且如果答案个数小于k,也要进入.. 然后就浪吧........... #inc…
http://www.lydsy.com/JudgeOnline/problem.php?id=3668 这题很简单.............. 枚举每一位然后累计即可.. QAQ,第一次以为能1A,但是wa了..噗,对拍才发现,自己有个地方打残了.. 还是得对拍啊.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream&g…
http://www.lydsy.com/JudgeOnline/problem.php?id=1685 由于每个小的都能整除大的,那么我们在取完大的以后(不超过c)后,再取一个最小的数来补充,可以证明这是最优的. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
http://www.lydsy.com/JudgeOnline/problem.php?id=3223 默默的.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> #include <set> #in…
http://www.lydsy.com/JudgeOnline/problem.php?id=1602 一开始以为直接暴力最短路,但是n<=1000, q<=1000可能会tle. 显然我没有看到树的性质,树边只有n-1,且一个点一定能到达另一个点 所以我们求出lca,然后记录从根到每个点的距离,然后答案就是d[u]+d[v]-2*d[lca(u, v)] 然后blabla就出来了 #include <cstdio> #include <cstring> #inclu…
http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小!当然是生成树!最小生成树! 边的还好做,但是这题有点,怎么办呢? 因为点在图中也起到连通作用,我们加个附加源,向每个点连边,价值为对应点权. ! 然后就ok了.. #include <cstdio> #include <cstring> #include <cmath>…
http://www.lydsy.com/JudgeOnline/problem.php?id=1503 这题没有看题解就1a了-好开心,, 其实后面去看题解发现他们的都很麻烦,其实有种很简单的做法: 题目要求全体人+和-,那么我们只用开变量m1来累计即可,由于splay的特殊性-我们将下界加上这个变量m1然后插入到splay中作为根,然后把左边的全部去掉即可---啦啦啦-.-然后出答案时,减去这个变量m1- 还有我们在插入一个新的工资时,要加上这个变量m1插入,要不然会被直接刷掉.... #i…
http://www.lydsy.com/JudgeOnline/problem.php?id=1269 这题RE2次啊,好不爽啊,我一直以为是splay的问题,其实是数组开小了......(我老犯这种低级错啊喂.. 和1507一样是模板题,指针版的速度依旧不行,,,,太慢了. #include <string> #include <cstdio> #include <algorithm> using namespace std; char strI[1024*1024…
题目 传送门:QWQ 分析 k短路,Astar.估价函数是终点向外跑的最短路. 显然不是正解qwq. 代码 // By noble_ // Astar algorithm // #include <bits/stdc++.h> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <vector> using namesp…
http://www.lydsy.com/JudgeOnline/problem.php?id=1010 蛋疼用latex写了份题解.. 2015.03.07 upd:很多东西可能有问题,最好看下边提供的链接的题解 参考:http://www.cnblogs.com/proverbs/archive/2012/10/06/2713109.html #include <cstdio> #include <cstring> #include <cmath> #include…
http://www.lydsy.com/JudgeOnline/problem.php?id=1034 弱的比弱的强就用,强的比强的强就用: 否则弱的和强的比. 输的情况就是2n-ans(b,a),因为总分是2n #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm>…
http://www.lydsy.com/JudgeOnline/problem.php?id=1011 题意:$f[i] = \sum_{j=1}^{i-1} \frac{M[i]M[j]}{i-j}$,求$1<=n<=10^5$的所有$f[i]$ orz 神题啊... 第一次做这种近似的题orz 首先n^2肯定是不可做的.. 然后看了题解.. 好神 首先得到$f[i]$表示第$i$个的能量, $g[i]$为题目给的$A*i$ $$f[i]=M_i \times \sum_{j=1}^{g[…
http://www.lydsy.com/JudgeOnline/problem.php?id=1677 完全背包很容易想到,将1,2,4...等作为物品容量即可. 然后这题还有一个递推式 f[i]==f[i-1], 当i%2==1 f[i]==f[i-1]+f[i/2], 当i%2==0 当i为奇数时,我们可以看为i-1加上一个1的情况,那么只有f[i-1]中情况(因为每种情况只是多了一个1) 当i为偶数时,分为2种情况,含有1和不含有1,当含有1时,那么情况就是f[i-1],当不含有1时,情…
题目 传送门:QWQ 分析 (sb如我写了发不知道什么东西在洛谷上竟然水了84分 嗯咳 设$ i $为双重回文的中心 如果$ j~i $ 可以被算作答案,只有满足如下两式: $ p[j]+j \geq i $ $ 2*(i-j) \leq p[j] $ 计算时我们先做一次马拉车,然后按照 $ p[j]+j \geq i $排序,保证它的单调,接着把满足$ 2*(i-j) \leq p[j] $扔进set里询问. 代码 #include <bits/stdc++.h> using namespa…
题目 传送门:QWQ 分析 在下面维护一个凸壳 好久没写博客了...... 代码 #include <bits/stdc++.h> using namespace std; ; ,INF=1e10; struct Line{ double a,b;int n; }l[maxn]; Line st[maxn];; bool cmp(Line a,Line b){ if(fabs(a.a-b.a)<eps)return a.b<b.b; return a.a<b.a; } boo…
http://www.lydsy.com/JudgeOnline/problem.php?id=1632 我简直是个sb... ... bfs都不会写.. 算方案还用2个bfs! 都不会整合到一个! 然后赤裸裸的wa了. 然后对拍... 噗 果然错的地方很... .. 然后貌似自己想改bfs,只需一个就行了.. 而且方案也改对了???? 然后不知哪里写挫了...然后样例过不了了.. 然后无奈看别人题解了... QAQ 噗,方案和我想的一样,但是...............我忘记了个东西,,标记…
http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using na…
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> using namespace s…
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也可以用以前的(多生产的).每单位产品保存一天的费用是s.求最小费用 显然贪心,每次查找之前有没有哪一天保存到现在的价值最小,然后比较更新.. #include <cstdio> #include <cstring> #include <cmath> #include <…
http://www.lydsy.com/JudgeOnline/problem.php?id=3296 显然,每群能交流的群是个强联通块 然后求出scc的数量,答案就是scc-1 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <qu…
http://www.lydsy.com/JudgeOnline/problem.php?id=3538 题意不要理解错QAQ,是说当前边(u,v)且u到n的最短距离中包含这条边,那么这条边就不警告. 那么我们反向spfa两次,然后再正向spfa就行了 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #inclu…
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include…