- 博客(12)
- 收藏
- 关注
原创 康托展开
康托展开可以用来表示一个数字只出现一次的状态(也就是n的排列),应用于dp或者搜索里面的状态压缩。一个排列对应的数字是这个排列在全排列中的字典序排名 例如:(1,2,3,4)(1, 2, 3, 4)(1,2,3,4) 可以用 000 来表示,(1,2,4,3)(1, 2, 4, 3)(1,2,4,3) 可以用 111 来表示 康托展开: int fac[] = {1, 1, 2, 6, 24,...
2019-04-27 15:41:23
217
原创 翻转问题
给你一排硬币,每次翻转一个硬币的时候它后面的两个硬币也会跟着翻转,问将这一排硬币全部翻为正面向上的最少次数是多少。 这是一个经典的翻转问题,经过分析可以得到以下的性质: 一个位置被翻转 nnn 次等价于被翻转 n%2n \% 2n%2 次 翻转的先后顺序不会影响结果 由以上性质可以得出此题翻转策略: 一个位置最多被翻转两次,多了是没有意义的 因为第一个硬币只有翻转第一个硬币才能改变,所以...
2019-04-23 21:00:46
825
原创 CSP 201509-4 高速公路
#include <cstdio> #include <stack> #include <cstring> #include <climits> #include <algorithm> const int MAXN = 1e4 + 2; const int MAXM = 1e5 + 2;
2018-12-11 21:34:06
486
原创 CSP 201703-4 地铁修建
最小生成树找瓶颈边 #include <cstdio> #include <algorithm> const int MAXN = 1e5 + 2; const int MAXM = 2e5 + 2; struct Edge { int a, b, w; bool operator < (const Edge &a) const { return w...
2018-12-10 17:38:16
299
原创 CSP 201609-3 炉石传说
大模拟,一开始写完只有70分,发现是英雄死了之后我忘了输出随从状态了。。。。 #include <iostream> #include <vector> #include <string> using namespace std; struct Minion { int atk, hel; Minion(int a = 0, int b =...
2018-11-30 19:52:14
391
原创 CSP 201809-4 再卖菜
dfs的时候注意记忆化搜索,不然会T掉只有80分。 记忆化搜索的时候保存一个数组 fi,j,kf_{i,j,k}fi,j,k 保存填第 iii 天时,前两天所填的数字有没有被搜索过 #include <cstdio> #include <cstdlib> const int MAXN = 300 + 5; int n, cnt; int a[MAXN], b[MAX...
2018-11-29 20:49:21
759
2
原创 Codeforces Round #508 (Div. 2)
A. Equality 因为是子序列,所以只要判断前 kkk 个字母最多组成多少个子序列就行了 #include <iostream> #include <climits> #include <algorithm> const int MAXN = 1e5 + 2; std::string str; int n, k, ans = INT_MAX; int ...
2018-10-29 18:55:46
166
原创 [kuangbin带你飞]专题四 最短路练习
Til the Cows Come Home 题意为问 NNN 到 111 的最短距离,直接套模板求单源最短路就好 #include <cstdio> #include <algorithm> #include <queue> #include &lt
2018-10-24 16:49:56
351
原创 [kuangbin带你飞]专题五 并查集
Wireless Network 裸的并查集,每次修好一个点之后就扫一遍,将它与在它连接范围内的之前就修好的点进行合并,唯一需要注意的点就是可以用点之间距离的平方来避免精度问题 #include <cstdio> #include <iostream> #include <cmath> const int MAXN = 10000 + 5; struct P...
2018-10-23 22:34:28
306
原创 Codeforces Round #511 (Div. 2)
A 题意为将 nnn 分为 333 个数,并保证 333 个数中都不是 333 的倍数,直接分为两个 111 ,如果剩下的 n−2n - 2n−2 是 333 的倍数,就分成 111、222 、n−3n - 3n−3 #include <cstdio> #include <algorithm> int n; int main() { scanf("%d", &a...
2018-10-23 19:37:36
152
原创 Codeforces Round #516 (Div. 2)
A 题意是增加边的长度使这三条边可以组成三角形,所以只要将较小的两条边之和增加到比最大边大1即可 #include <cstdio> #include <algorithm> int ans; int a[5]; int main() { scanf("%d %d %d", &a[1], &a[2], &a[3]); std::s...
2018-10-22 22:12:03
199
原创 Codeforces Round #512 (Div. 2)
A 水题,数据中有1就是HARD,没有就是EASY #include &lt;cstdio&gt; int n; bool ok = false; int main() { scanf("%d", &amp;n); while (n--) { int a; scanf("%d", &amp;a); if (
2018-10-22 21:49:46
200
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅