
Codeforces
文章平均质量分 80
synapse7
这个作者很懒,什么都没留下…
展开
-
基于链表实现的珂朵莉树
以下内容基于 CF896C Willem, Chtholly and Seniorious 来介绍。珂朵莉树实质上是一种可以维护区间上的分裂与合并的数据结构,但要求数据是随机的,或者有大量的随机合并操作,这样才能保证维护的区间个数是一个很小的值。一开始,我们用不同的节点表示 [1,1],[2,2],...,[n,n][1,1],[2,2],...,[n,n][1,1],[2,2],...,[n...原创 2019-10-29 22:18:17 · 754 阅读 · 1 评论 -
Codeforces 1251D Salary Changing (二分+最大化中位数)
https://codeforces.com/problemset/problem/1251/D提供一个比官方题解还简洁的二分思路。首先,中位数越大,发出的工资越多,这满足二分条件。于是二分中位数,判断所发工资是否不超过 sss,整个过程如下:二分前预处理,将数据按照 lll 从大到小排序,另外还需计算基础工资之和 baseCostbaseCostbaseCost,即所有 lll 之和...原创 2019-10-28 18:10:16 · 573 阅读 · 0 评论 -
Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)
A. Secretshttp://codeforces.com/contest/333/problem/Atime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGe原创 2013-08-17 16:57:22 · 1891 阅读 · 0 评论 -
Codeforces Round #100 / 140A (简单几何)
http://codeforces.com/contest/140/problem/A过大圆圆心作小圆切线即可发现规律,详见代码。注意判相等一定要用fabs!!!完整代码:/*30ms,0KB*/#includeusing namespace std;int main(){ int n, R, r; double a; scanf("%d%d%d"原创 2013-12-08 15:31:03 · 1284 阅读 · 5 评论 -
Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)
A. Cut Ribbonhttp://codeforces.com/problemset/problem/189/Atime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-29 21:19:33 · 2568 阅读 · 0 评论 -
【优化】Codeforces Beta Round #1 / 1B Spreadsheets (字符串处理)
B. Spreadsheetshttp://codeforces.com/problemset/problem/1/Btime limit per test10 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output原创 2013-08-18 11:06:34 · 1465 阅读 · 0 评论 -
Codeforces Round #218 (Div. 2) / 371C Hamburgers (二分)
http://codeforces.com/contest/371/problem/C直接二分能做的汉堡数,注意上界要开大一点。完整代码:/*15ms,0KB*/#includeusing namespace std;const long long mx = 1e13;///多开一位,因为结果可以略大于1e12const char b[] = "BSC";原创 2014-03-12 12:15:33 · 1002 阅读 · 0 评论 -
Codeforces Round #218 (Div. 2) / 371B Fox Dividing Cheese (想法题)
http://codeforces.com/contest/371/problem/B神题必有神解——你能想到这么做吗?/*15ms,0KB*/#includeusing namespace std;int op_cnt[6];int main(){ int a, b, ans = 0; cin >> a >> b; for (int n = 2; n <=原创 2014-03-12 12:59:43 · 1612 阅读 · 0 评论 -
Codeforces Round #120 (Div. 2) / 190D Non-Secret Cypher (计数&two pointers)
http://codeforces.com/contest/190/problem/D【神题必有神解】从这一题可大题了解two pointers算法的威力。/*1024ms,42062KB*/#includeusing namespace std;const int mx = 400005;int a[mx];map mp;/*数据例子:10 22 3原创 2014-03-12 19:54:31 · 1543 阅读 · 0 评论 -
Codeforces Round #209 (Div. 2) / 359D Pair of Numbers (一点点想法)
http://codeforces.com/problemset/problem/359/D/*124ms,2300KB*/#includeint a[300005], w[300005];int main(){ int n, i, l, r, cnt = 0, maxd = 0; scanf("%d", &n); for (i = 0; i < n; i++) s原创 2014-03-12 21:25:26 · 1166 阅读 · 0 评论 -
Codeforces Round #205 (Div. 2) / 353C Find Maximum (贪心)
C. Find Maximumhttp://codeforces.com/problemset/problem/353/Ctime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-10-19 18:23:14 · 1512 阅读 · 0 评论 -
Codeforces Round #177 (Div. 1) / 288A Polo the Penguin and Strings(贪心)
A. Polo the Penguin and Stringshttp://codeforces.com/problemset/problem/288/Atime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutput原创 2013-08-14 10:04:17 · 1859 阅读 · 0 评论 -
Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)
A. Insomnia curehttp://codeforces.com/problemset/problem/148/Atime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-24 09:53:59 · 2354 阅读 · 0 评论 -
Codeforces Beta Round #75 (Div. 2) / 92B Binary Number(贪心)
B. Binary Numberhttp://codeforces.com/problemset/problem/92/Btime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-17 23:33:29 · 1841 阅读 · 0 评论 -
Codeforces Round #196 (Div. 2) / 337A Puzzles (搜索)
A. Puzzleshttp://codeforces.com/contest/337/problem/Atime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTh原创 2013-08-17 10:48:26 · 1438 阅读 · 0 评论 -
Codeforces Round #196 (Div. 2) / 337B Routine Problem(数学)
B. Routine Problemhttp://codeforces.com/contest/337/problem/Btime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-17 10:25:46 · 1345 阅读 · 0 评论 -
Codeforces Beta Round #36 / 36A Extra-terrestrial Intelligence(模拟)
A. Extra-terrestrial Intelligencehttp://codeforces.com/problemset/problem/36/Atime limit per test2 secondsmemory limit per test64 megabytesinputinput.txtoutputoutpu原创 2013-08-16 13:56:22 · 1265 阅读 · 0 评论 -
Codeforces Round #152 (Div. 2) / 248B Chilly Willy (数论)
B. Chilly Willyhttp://codeforces.com/problemset/problem/248/Btime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-30 09:19:50 · 1529 阅读 · 0 评论 -
Codeforces Round #147 (Div. 2) / 237A Free Cash (模拟)
A. Free Cashhttp://codeforces.com/problemset/problem/237/Atime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-31 21:22:42 · 1425 阅读 · 0 评论 -
Codeforces Round #131 (Div. 2) / 214A System of Equations(枚举&优化)
A. System of Equationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFurik loves math lessons very much,原创 2013-08-25 14:20:28 · 1345 阅读 · 0 评论 -
Codeforces Round #188 (Div. 1) / 317A Perfect Pair(数学&优化)
A. Perfect Pairhttp://codeforces.com/problemset/problem/317/Atime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output原创 2013-08-16 23:51:53 · 1188 阅读 · 0 评论 -
Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)
http://codeforces.com/problemset/problem/401/D解释全部在代码的注释中:/*78ms,205464KB*/#includeusing namespace std;const int mx = 1 << 18;long long dp[mx][100];///dp[mask][j]表示余数为j时的mask对应的x的个数///原创 2014-03-11 20:25:34 · 2099 阅读 · 0 评论 -
Codeforces Round #196 (Div. 2) / 337D Book of Evil (树的直径变形——树的最长标记弦)
http://codeforces.com/contest/337/problem/D/*154ms,10300KB*/#includeusing namespace std;const int mx = 100005;vector g[mx];int d1[mx], d2[mx], p[mx];void dfs(int p, int u, int deep, i原创 2014-03-13 16:05:58 · 953 阅读 · 0 评论 -
Codeforces Beta Round #87 (Div. 2) / 116C Party (DFS&树的最大深度)
http://codeforces.com/problemset/problem/116/C从树根DFS,看最大能递归几层。/*30ms,300KB*/#includeusing namespace std;const int mx = 2005;vector v[mx];bool fa[mx];int maxlen;void dfs(int i, int原创 2014-03-09 10:28:20 · 1313 阅读 · 0 评论 -
Codeforces Round #183 (Div. 1) / 303A Lucky Permutation Triple (强大的数学&想法题)
http://codeforces.com/problemset/problem/303/Awhen n is odd, A[i] = B[i] = iwhen n is even, there is no solution.why? If , then or just , where S = 0 + 1 + ... + n - 1 = n(n - 1) /原创 2014-03-15 12:35:29 · 1820 阅读 · 0 评论 -
Codeforces Round #185 (Div. 1) / 311A The Closest Pair (“陷阱”题)
http://codeforces.com/problemset/problem/311/AIf we ignore "break", tot will be up to .Consider whether we can make such inequality d ≤ p[j].x - p[i].x is always false. The obvious way原创 2014-03-15 13:15:35 · 1392 阅读 · 0 评论 -
Codeforces Round #198 (Div. 2) / 340A The Wall (数论)
A. The Wallhttp://codeforces.com/contest/340/problem/Atime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputI原创 2013-08-31 20:02:44 · 1052 阅读 · 0 评论 -
Codeforces Round #237 (Div. 2) / 404C Restore Graph (构造最短路径树)
http://codeforces.com/contest/404/problem/C思路:我们构造一颗最短路径树就行了。若能够构造,边数必然为n-1(样例1的边数可以是两条)。如何构造?从距离为1的点开始,逐渐往下加边,生成一颗k叉树。若在中间生成了大于k的叉,则输出-1。完整代码:/*265ms,4436KB*/#includeusing namesp原创 2014-03-20 09:28:28 · 1741 阅读 · 0 评论 -
Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)
http://codeforces.com/contest/387/problem/C/*31ms,100KB*/#includechar str[100005];int main(){ gets(str); int i, j, res = 0; for (i = 0; str[i]; i = j) { for (j = i + 1; str[j] == '0原创 2014-03-22 18:12:42 · 1232 阅读 · 0 评论 -
Codeforces Round #237 (Div. 2) / 404B Marathon (fmod或long long表示浮点)
http://codeforces.com/contest/404/problem/B/*124ms,0KB*/#includeusing namespace std;double a;void f(double len){ int c = ((int)(len / a)) % 4; len = fmod(len, a); if (c == 0) printf("原创 2014-03-20 09:40:48 · 1169 阅读 · 0 评论 -
Manacher 算法详解:O(n) 复杂度求最长回文子串
先预处理下:在每个字符的两边都插入一个特殊的符号,比如abba变成#a#b#b#a#,aba变成#a#b#a#(因为Manacher算法只能处理奇数长度的字符串)。同时,为了避免数组越界,在字符串开头添加另一特殊符号,比如$#a#b#a#。以字符串3212343219为例,处理后变成S[] = "$#3#2#1#2#3#4#3#2#1#9#"。然后用一个数组Len[i]来记录以字符S[i原创 2014-02-03 12:27:09 · 4408 阅读 · 2 评论 -
Codeforces Round #217 (Div. 2) / 370C Mittens (构造&贪心)
http://codeforces.com/contest/370/problem/C/*31ms,0KB*/#include#includeusing namespace std;int C[5005];int main(){ int N, M; cin >> N >> M; for (int i = 0; i > C[i]; sort(C, C + N原创 2014-03-14 20:07:18 · 1296 阅读 · 0 评论 -
Codeforces Round #197 (Div. 2) / 339C Xenia and Weights (爆搜)
http://codeforces.com/contest/339/problem/C爆搜水过,复杂度貌似是O(m)的?/*62ms,4KBm*/#includeint m, ans[1005]; ///ans从1开始char s[15];bool ok;///O(m)复杂度?int dfs(int deep, int diff) /// diff表示重量之差{原创 2014-03-14 16:24:46 · 1354 阅读 · 0 评论 -
Codeforces Beta Round #87 (Div. 2) / 116D Lawnmower (讨论情况)
http://codeforces.com/problemset/problem/116/D/*30ms,0KB*/#includeconst int mx = 155;char g[mx][mx];int left[mx], right[mx];int main(){ int n, m, i, j, posy, dir; int cnt = -1; scanf原创 2014-03-09 10:38:40 · 1158 阅读 · 0 评论 -
CROC-MBTU 2012, Elimination Round / 245D Restoring Table (位运算)
http://codeforces.com/problemset/problem/245/D/*30ms,0KB*/#includeusing namespace std;const int mx = 105;int m[mx][mx],a[mx];int main(){ int n, i, j; scanf("%d", &n); for (i = 1; i原创 2014-03-09 10:57:53 · 996 阅读 · 0 评论 -
CROC-MBTU 2012, Elimination Round / 245F Log Stream Analysis (日期处理&二分)
http://codeforces.com/problemset/problem/245/F#includeusing namespace std;const int mx = 5000005;const int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int day2s = 24原创 2014-03-09 10:55:09 · 1306 阅读 · 0 评论 -
Codeforces Round #198 (Div. 2) / 340B Maximal Area Quadrilateral (点集中的最大四边形)
http://codeforces.com/contest/340/problem/B枚举一条线段,再枚举这条线段左右两边的三角形,拼起来就是一个四边形了。完整代码:/*186ms,0KB*/#includeusing namespace std;int x[300], y[300], A[2];int main(){ int n, i, j, k,原创 2014-03-14 14:19:20 · 1208 阅读 · 0 评论 -
Codeforces Round #217 (Div. 2) / 370B Berland Bingo (set_union)
http://codeforces.com/contest/370/problem/B/*15ms,200KB*/#includeusing namespace std;vector v[105], tmp(105);int main(){ int n, i, j, k, x; scanf("%d", &n); for (i = 0; i < n; ++i) {原创 2014-03-14 16:57:41 · 1242 阅读 · 0 评论 -
Codeforces Round #206 (Div. 2) / 355C (转化&枚举)
http://codeforces.com/contest/355/problem/C枚举i,左手操作了i次,右手操作了n-i次,然后重复次数可以直接算出来,所以答案就可以在O(n)的时间内算出来。/*30ms,4000KB*/#includeusing namespace std;int a[100005];int main(){ int n, l, r,原创 2014-03-14 20:17:32 · 1001 阅读 · 0 评论 -
Codeforces Beta Round #87 (Div. 2) / 116B Little Pigs and Wolves (简单匹配)
http://codeforces.com/problemset/problem/116/B开始还打算打匈牙利的。。结果看到了这句话:“there will be at most one wolf adjacent to each little pig”也就是说,对于每头狼,若它周围有猪,就++cnt因为不会出现两头狼吃同一只猪的情况。完整代码:/*30ms原创 2014-03-09 10:35:15 · 1407 阅读 · 0 评论