自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(46)
  • 资源 (1)
  • 收藏
  • 关注

原创 Gym - 101775J Straight Master——差分

题意:给你一个序列,每次可以随便选一个大小为3~5的区间,将区间内的数减1,问最后能不能把整个序列变为0思路:构造差分序列b【i】=a【i】-a【i-1】,比如1 3 2 5 1的差分序列就是1 2 -1 3 -4,这样将区间【l,r】内的所有数减一相当于把b【l】减一, 把b【r+1】加一,基于这个思想我们从左到右扫整个序列,遇到正数就找他右面离他最近的负数,把这个负数尽量变为0,变为0后若...

2018-08-31 23:51:31 609

原创 Black or White Aizu - 1382——dp

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;//dp[i]:前i个位置染完的最小花费//dp[0] = 0, dp[others] = INF//if(a[i] == b[i]) dp[i] ...

2018-08-28 12:20:35 480

原创 UVALive 2995 Image Is Everything——模拟

建立视图和矩阵之间的对应关系,然后模拟#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define rep(i, x, y) for (int i = x; i < y; i++)using namespace std;con...

2018-08-27 11:56:30 203

原创 UVALive 8273 Assigning Frequencies——搜索

先搞出一个dfs序,然后在dfs序上爆搜,会发现跑的时候实际上有各种剪枝,3ms就A了。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 30;int T, ...

2018-08-27 00:34:16 260

原创 UVALive - 4731 Cellular Network——概率dp

从大到小排个序,然后随便dp一下就出来了#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 110;const int INF = 0x3f3f3f3f;doub...

2018-08-26 13:34:46 164

原创 UVA 11404 Palindromic Subsequence——dp

正反来一遍LCS就好了,然而没想到什么打印解的好办法,就拿string爆了一下。。。随机测试的时候发现这样跑出来的有的不是回文串,不过前一半是回文串的一半,所以把前一半正反输出一遍就好了#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>...

2018-08-25 20:55:09 158

原创 UVA 11552 Fewest Flops——dp

注意当前块结尾字符若等于前一个块的结尾字符,要判一下当前块的字符总数是否为1#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1010;const int INF...

2018-08-24 17:55:59 155

原创 UVALive 4256 Salesmen——dp

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;int T, n, m, L, a[210];...

2018-08-24 17:12:05 169

原创 HDU 5886 Tower Defence——dp

预处理出最长链,若断边不在最长链上,那么答案依旧是最长链,否则计算断开后的最长链,这个做一次树形dp就可以了#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll...

2018-08-24 16:13:32 226

原创 HDU 5883 HDU - 5883——欧拉路

注意判一下欧拉回路的情况,这种情况下需要找一个点再异或一次#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e5 + 10;const int maxm = 1...

2018-08-24 13:39:49 219

原创 HDU 5884 Sort——二分+O(n)哈弗曼树

两个队列搞一搞就搞出O(n)的哈弗曼树了#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;char ...

2018-08-24 12:22:56 130

原创 UVALive 4794 Sharing Chocolate——dp

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;bool judge[(1<<15)+10];int kase, N, X, Y, a[20], sum[(1<<15)+10...

2018-08-23 22:04:01 174

原创 HDU 5887 Herbs Gathering——剪枝

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;ll N, V, MAX;struct Data {...

2018-08-23 20:53:16 186

原创 UVALive 3983 Robotruck——单调队列优化dp

注意一下一开始要把原点入队#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;const int maxn = 1e5 + 10;int T, C, n...

2018-08-23 10:13:28 229

原创 HDU 6434 Problem I. Count

#include<bits/stdc++.h>using namespace std;#define LL long longconst int N = 2e7;const int maxn = N+10;int T,n;int primes,prime[maxn],phi[maxn];bool vis[maxn];LL ans[maxn];void init...

2018-08-22 22:14:49 220

原创 HDU 6437 Problem L.Videos——费用流

s到每个人容量为1,费用为0的边每个人到每个视频建容量为1, 费用为0的边每个视频拆点,建容量为1,费用为-w的边视频之间若时间不覆盖,则容量为1的边,若两视频op相同,费用为W, 否则为0每个视频到t建容量为1, 费用为0的边跑一遍s-t最小费用流,答案取负即可#include <cstdio>#include <cstring>#inclu...

2018-08-22 21:25:20 276

原创 HDU 6435 Problem J. CSGO

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const ll INF = 1e16;int T, n, m, k, a[5];ll sum[(1&l...

2018-08-22 20:23:17 198

原创 UVA 10859 Placing Lampposts——dp

#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1010;int T, n, m;bool vi...

2018-08-21 22:00:53 134

原创 UVA 11825 Hackers' Crackdown——dp

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int kase, n, a[20], un[1<<16], dp[1<<16];int main() { while...

2018-08-21 10:29:40 148

原创 HDU 6415 Rikka with Nash Equilibrium——dp

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 81;int T, n, m, mod;ll dp[2][maxn][...

2018-08-20 21:40:28 230

原创 UVA 10891 Game of Sum——dp

定义dp[i][j]表示面对区间[i,j]的数执先手一方可获得的最大数字和注意题目描述貌似不太严谨,差距可以是负的,一开始加绝对值错了。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;ty...

2018-08-19 21:41:14 144

原创 HDU 5456 Matches Puzzle Game——数位dp

先把式子转化为B+C=A;然后用dp[i][j][0/1][0/1][0/1]表示A用了i根火柴棒,从低到高递推到第j位,上一位是否有进位,B是否用到了最高位,C是否用到了最高位的情况总数,最后统计一下dp[n][枚举位数][0][1][1]的和就好了#include <cstdio>#include <cstring>#include <iostream&...

2018-08-19 10:45:23 261

原创 HDU 1171 Big Event in HDU——二进制优化多重背包

因为甜品可以拆开,所以我们可以把问题转化成两次独立的多重背包,第一次求价值对应的最小体积,第二次求价值对应的最大体积,然后用第一次求得的体积在第二次的dp数组里找价值的最小值即可这里偷懒只用了二进制优化,跑得挺慢#include <cstdio>#include <cstring>#include <iostream>#include <a...

2018-08-17 10:09:14 232

原创 hdu 5880 Family View——AC自动机

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6 + 10;const int sz = 26;char str[maxn];int interval[m...

2018-08-16 12:21:55 184

原创 HDU 6390 GuGuFishtion——莫比乌斯反演

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e6 + 5;int mod;bool vis[maxn];int...

2018-08-16 00:49:31 215

原创 HDU 6400 Parentheses Matrix——构造

10 10的时候这么构造是14(()()()())()()()()()......()()()()()(()()()())但是下面这么构造是16((((((((((()()()()()......()()()()()))))))))))也就是说我们可以通过破坏首尾两行来获得更多的匹配列其余情况同理#include <cstdi...

2018-08-15 19:21:46 189

原创 HDU 1695 GCD——莫比乌斯反演

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;int cnt, prime[maxn], mu[ma...

2018-08-15 11:43:02 208

原创 HDU 5890 Eighty seven——bitset优化01背包

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <bitset>using namespace std;inline void input(int &x) { char c; x = ...

2018-08-15 00:27:54 284

原创 POJ 2443 Set Operation——bitset

printf比puts多6倍的常数。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <bitset>using namespace std;bitset<1010> bit[10010];...

2018-08-14 21:42:41 169

原创 HDU 6395 Sequence——分段矩阵快速幂

我是直接爆1~1e5,后面的分段矩阵快速幂,和我做法类似的可以拿我的代码去对拍#include <bits/stdc++.h>using namespace std;typedef long long ll;const ll mod = 1e9 + 7;const ll sz = 1e5;ll A, B, C, D, P, n, F[sz+10];struct Mat...

2018-08-14 00:47:15 275

原创 2017 乌鲁木齐区域赛 Sum of the Line——容斥

思路:先令 T 中所有位置的值为相应的c,那么答案为 1^2+2^2+...+k^2。下面考虑删去 T(r,c)=0 的位置造成的代价,也就是计算不和k互质的数对答案的贡献。略加思考就可以得到一个结论,删除第c个数(值肯定也为c)花费的代价一定是c^2暴力直接求的话会发现有的k的合数有上万个,铁定超时。考虑对k进行唯一分解,发现k分解后的素数最多也就九个,可以在2^9内用容斥原理进...

2018-08-13 01:20:20 555

原创 HDU 5458 Stability——双连通缩点+树链剖分

思路:首先将所有1操作的边都删去,然后倒着查询,遇到1操作就增边,最后倒着输出删去所有1操作后,我们对整个图进行双连通缩点,将图变成一棵树,所有边权都为1,查询的时候就是查询树上区间的和,更新便是将两点之间路径的边权全部变为0。这里可以用树链剖分+线段树做,注意一个小技巧,那就是我们可以用点权代表这个点与他父节点之间的边的边权,更新和查询的具体操作看树链剖分部分的代码吧。#include...

2018-08-12 10:25:02 272 3

原创 Codeforces Round #503 C. Elections

枚举2~m的最大票数,对于枚举的每个票数i,可以用优先队列以最小的代价构造出1号的胜局,然后在所有最小代价中取最小值即可#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 3010;const ll INF = 1e16;vector<int> v...

2018-08-12 09:41:41 466

原创 洛谷 P3384 【模板】树链剖分

#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e5 + 10;int n, m, r, p, a[maxn];int mem, head[maxn], id[maxn], idr[maxn];struct Edge { int to, next; }...

2018-08-11 19:32:22 109

原创 POJ 3352 Road Construction——边双连通分量

至少增加的边数 =( 缩点后树总度数为1的结点数 + 1 )/ 2#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;const int maxn= 1...

2018-08-11 10:10:33 156

原创 UVALive 5135 Mining Your Own Business——点双连通分量

https://blog.csdn.net/l123012013048/article/details/47347023点数可能大于边数,导致用n初始化不够,TLE了两发,改了memset过了#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e5 + 10...

2018-08-10 20:21:01 168

原创 POJ 2186 Popular Cows——Tarjan缩点

题意:有n头牛,m个崇拜关系,并且崇拜具有传递性,如果a崇拜b,b崇拜c,则a崇拜c,求最后有几头牛被所有牛崇拜。思路:显然一个强联通分量内的所有点都是满足条件的,我们可以对整张图进行缩点,然后就简单了。剩下的所有点都不是强连通的,现在整张图就是一个DAG(有向无环图)那么就变成一道水题了,因为这是一个有向无环图,不存在所有点的出度都不为零的情况。所以必然有1个及以上的点出度为...

2018-08-10 01:13:20 219

原创 洛谷P2863[USACO06JAN]牛的舞会The Cow Prom——强连通分量

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;const int maxn = 1e5 + 10;vector<int> G[maxn]...

2018-08-10 00:21:32 207

原创 HDU 6370 Werewolf——思路题

vector卡到绝望。。。。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;const int maxn = 1e5 + 10;int mem...

2018-08-09 01:42:32 518

原创 HDU 6350 Always Online——仙人掌图

思路:把每个环的最小边去掉,加在环的其他边上,然后并查集跑一下就可以,跑的时候维护一下某位为1的点有多少个#include <cstdio>#include <vector>#include <iostream>#include <algorithm>using namespace std;typedef unsigne...

2018-08-08 17:28:15 327

Qt游戏编程——飞机大战

游戏模板,大家可以随意添加自己的元素

2017-07-06

空空如也

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

TA关注的人

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