
Codeforces
文章平均质量分 78
01的世界
有时,失去了才懂得珍惜
展开
-
codeforces 306 div.2 B. Preparing Olympiad
B. Preparing Olympiadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n problems. You have estimated the dif原创 2015-07-24 00:42:39 · 382 阅读 · 0 评论 -
Codeforces 611C New Year and Domino(dp)
C. New Year and Dominotime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThey say "years are like dominoes, tumbling on原创 2015-12-31 22:18:58 · 569 阅读 · 0 评论 -
Codeforces 609D 贪心+二分
D. Gadgets for dollars and poundstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNura wants to buy k gadgets. She ha原创 2015-12-23 23:14:46 · 503 阅读 · 0 评论 -
Codeforces 601A Dijkstra最短路
题意:有个地方有些城镇,城镇与城镇间如果有铁路相连,就不会有公路相连,没有铁路连接的城镇就会有公路相连。给你n个城镇数目,m铁路线,问同时从1出发,分别坐火车和坐汽车到达n点,两者都到达的时候最少的用时。其中火车和汽车不能同时到达中间点。分析:题目中的要求不能同时到达某个中间点,这该怎么办呢,刚开始我就想找出最短路径,然后遍历一下两条路径是否经过同时同一点,但仔细想想发现这是不必要的,因为公路原创 2015-12-08 13:03:00 · 987 阅读 · 0 评论 -
Codeforces 608B 找规律
B. Hamming Distance Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGenos needs your help. He was asked to solve原创 2015-12-24 18:36:35 · 864 阅读 · 0 评论 -
Codeforces 607A dp
A. Chain Reactiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n beacons located at distinct positions o原创 2015-12-24 21:32:23 · 631 阅读 · 2 评论 -
codeforces 602B
题意:有n个数字,找出最长的一段连续的序列,要求这个序列的最大数和最小数相差不能大于1分析:一段序列,可能有的会重复,那么就压缩一下,把连续的相同的数字压缩为一个,并记录数字个数,这样在从头走一遍就好了。/*Sample test(s)Input51 2 3 3 2Output4Input115 4 5 5 6 7 8 8 8 7原创 2015-12-08 10:13:27 · 585 阅读 · 0 评论 -
Codeforces 533B 树上的dp(求最大偶数个节点的权重和)
题目:点击打开链接题意:给你n个节点,每个节点已知父亲和权值,1节点为根必选,你从中挑选节点,以每个节点为父亲的子节点个数和必须为偶数,问最大的权值和分析:从叶子结点,更新他的父节点,直到跟新到树根。f[i][0]表示以i节点为树根的节点数为偶数个的最大权值和f[i][0]表示以i节点为树根的节点数为奇数个的最大权值和状态转移方程就是,如果是奇数个再加上一个节点原创 2016-03-01 20:40:26 · 1120 阅读 · 0 评论 -
Codeforces 620D STL+二分
题目:620D - Professor GukiZ and Two Arrays题意:交换两数组中的元素最多两次,使两数组差值最小 分析:对于0次和1次的情况,元素2000个,暴力枚举就行,但是对于交换两次的,因为交换方案也有很多种情况,预测也是暴力,但怎么暴力呢?看了题目的标签是二分,也往这方面考虑。想了很久,不会啊(囧),看了大神的博客:http://www.cnblo原创 2016-03-18 00:27:33 · 666 阅读 · 0 评论 -
Codeforces 527C 线段树 /set
题目:http://codeforces.com/problemset/problem/527/C题意:给出矩形的长和高,然后给出一些操作,水平或者竖直切割矩形,每切割一次,求出剩下的面积最大的矩形分析:看到题目,就想到是如何维护区间的最大值,第一想到的就是线段树,可以把还可以划线点的用1表示,划了线的用0表示,然后求最大长度就是如何求连续的1的最大个数,那么这题的变成了一原创 2016-03-05 22:52:45 · 448 阅读 · 0 评论 -
Codeforces 620E New Year Tree
http://codeforces.com/problemset/problem/620/E题意: 给以一棵树,每个结点刚开始的时候都有一个颜色,现在有查询1 u col:给这个结点及其子树染上col这种颜色,2 u:查询以u为根节点的子树的所有颜色种类分析: 显然是到线段树的题目,要把每个节点的子树放到一个区间上,并且记录首尾位置,这样就可以更新颜色的时候成段更新,查询颜色种类的时候区间查询。原创 2016-03-18 13:06:31 · 680 阅读 · 0 评论 -
Codeforces 629D - Babaei and Birthday Cake 线段树
题目:629D - Babaei and Birthday Cake 题意:给你1-n个圆柱体,要求从1-n,选择一些体积逐渐增大的圆柱体,使得所选的圆柱体体积之和最大。分析:看到这题,n的数据范围1e5,感觉会超时,于是很快用n^2的dp敲完,超时。。。O(n^2)的状态转移方程:dp[i]表示到i圆柱体最大的体积和if(val[i]>val[j]){dp[i]=max(dp原创 2016-02-23 22:10:06 · 408 阅读 · 0 评论 -
Codeforces 629C - Famil Door and Brackets dp
题目:629C - Famil Door and Brackets题意:给出长度为m的含有()的字符串s,要求在s的前面和后面各加上一个字符串p,q(可以是空串),构成长度为n的合法串。分析:合法串就是对于任意位置的括号前缀和大于等于0,且最后的前缀和为0。枚举这个字符串前面p字符串的长度,可以使得p字符串的前缀和大于等于字符串s的最小前缀和minn,那么p+s就符合前缀和原创 2016-02-24 13:33:58 · 328 阅读 · 0 评论 -
Educational Codeforces Round 7 Codeforces 622D Codeforces 622E
题目:622CNot Equal on a Segment分析:对于这题,对于连续相等数字做一下压缩处理,如果相等的直接跳到下一个不等的位置在比较就好了,O(N)的时间压缩预处理,查询O(1)。题目:622DOptimal Number Permutation分析:这是道找规原创 2016-03-11 09:41:28 · 391 阅读 · 0 评论 -
Codeforces 623A 623B dp
题目:623AGraph and String题意:题目要求a,b,c,三个字母,如果相邻或者相等就连一条边,现在给你边,问是否存在这样的数组。分析:可以反着考虑,可见,如果没边,那么一定是a和c相邻,b无论跟谁相邻都会有边,所以O(n^2)遍历找到没边的两点,分别给这两点填上a或者c,这是如果a,c已经填上了同一种颜色,那么肯定原创 2016-03-11 16:54:41 · 704 阅读 · 0 评论 -
Codeforces 625B - War of the Corporations
625B - War of the Corporations分析:KMP,找出模式串在主串中出现的位置,然后总的个数减去重叠的个数就行#include #include using namespace std;const int N = 100002;int next[33];char S[N], T[33];int slen, tlen;int a[N],cnt;voi原创 2016-02-09 12:33:53 · 424 阅读 · 0 评论 -
Codeforces 627B Factory Repairs 线段树
题目:627B - Factory RepairsInputThe first line contains five integers n,k, a,b, and q (1 ≤ k ≤ n ≤ 200 000,1 ≤ b a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repa原创 2016-03-15 12:31:40 · 458 阅读 · 0 评论 -
Codeforces 598D Igor In the Museum (dfs)
Igor is in the museum and he wants to see as many pictures as possible.Museum can be represented as a rectangular field of n × m cells. Each cell is either empty or impassable. Empty cells are marked原创 2016-01-16 14:47:08 · 447 阅读 · 0 评论 -
Codeforces 610С — Harmony Analysis 找规律
Codeforces Round #337 (Div. 2) C. Harmony Analysistime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe semester i原创 2015-12-27 23:12:01 · 3885 阅读 · 0 评论 -
Codeforces 605A
题意:有n个数字组成的序列,每次可以把序列中的某个数放到开头或者尾部,问最少需要多少次操作才能使序列从小到大排列分析:不需要移动的元素是在排列后的序列与排列前的序列的相对位置不变的的序列,在排列后连续的一段序列,如果他们原先的位置是递增的,那么他们是不需要移动的,因为只要把他们之间的元素移走就好了,我们要找的就是最长的一段这样的连续序列。这段序列是不需要移动的。#include原创 2015-12-10 20:27:09 · 506 阅读 · 0 评论 -
Codeforces Round #316 (Div. 2)
地址:点击打开链接这个相对简单,自己做了3题。570А — Elections分析:简单的数组操作就OK了#include #include #include #include using namespace std;int n,m,a[105];int main(){ while(cin>>n>>m){ memset(a,0,原创 2015-08-28 10:48:59 · 337 阅读 · 0 评论 -
Editorial Codeforces Round #Pi
#include#include#include#include#includeusing namespace std;int a[100005];int n,minn,maxn;int main(){ while(cin>>n){ for(int i=1;i<=n;i++) cin>>a[i]; cout<<a[2原创 2015-08-30 10:29:45 · 257 阅读 · 0 评论 -
Codeforces 583c GCD Table
C. GCD Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe GCD table G of size n × n for an array of positive原创 2015-10-04 21:50:04 · 546 阅读 · 0 评论 -
Codeforces Round #320 DIV.2
分析:细菌每次一天一分为二,给定希望看到的细菌个数,求需要放多少个细菌。1,2,4,8,16.......细菌个数每天加倍增长。#includeusing namespace std;int main(){ int x; cin>>x; int flag=1; while(x>1){ if(x%2==1)flag++; //如果x是奇数,就需原创 2015-09-17 20:00:28 · 309 阅读 · 0 评论 -
Codeforces 307div.2
C. GukiZ hates Boxestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ is concerned about making his wa原创 2015-08-08 16:50:35 · 292 阅读 · 0 评论 -
Codeforces Round #310
题目;Codeforces Round #310的#includeusing namespace std;int a[2];int x;int main(){ int n; scanf("%d",&n); a[0]=a[1]=0; string s; cin>>s; for(int i=0;i<n;i++){ a[s原创 2015-09-04 17:51:18 · 272 阅读 · 0 评论 -
Codeforces Round #326 (div2)
1001.题解:Idea is a simple greedy, buy needed meat for i - th day when it's cheapest among days1, 2, ..., n.So, the pseudo code below will work:ans = 0price = infinityfor i = 1 to n原创 2015-10-16 22:45:45 · 308 阅读 · 0 评论 -
Codeforces 590A Median Smoothing
题意; 给你一个0 1序列,首尾元素保持不变,从2-n-1,变成a[i-1]+a[i]+a[i-1]/2,问经过多少次不再改变,求出最后的序列。分析:一个元素可以改变,只有他和左右的都不相同才行,这样原来的序列,就可以分成好多段01序列段,只有这种01交替变换的才能够改变,不是这种串不能改变,这样改变的次数就是最长的01变化的串。改变的时候如果首尾元素相同,全部就变成首尾元素,如果首尾元素不同原创 2015-10-26 15:49:15 · 479 阅读 · 0 评论 -
Codeforces 577B Modulo Sum 动态规划基础
B. Modulo Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of numbers a1, a2, ..., an, an原创 2015-09-20 19:53:20 · 1178 阅读 · 0 评论 -
Codeforces Round #325 (Div. 2)
1001.题目:A. Alena's Schedule分析:简单题,模拟一下就好了。#include#define LL long longusing namespace std;int a[102];int main(){ // ios::sync_with_stdio(false); int n; cin>>n; for(int i=0;i<原创 2015-10-13 13:07:47 · 300 阅读 · 0 评论 -
Codeforces 475A (五一训练 L)
A. Bayan Bustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe final round of Bayan Programming Contest will be hel原创 2015-05-07 00:11:06 · 346 阅读 · 0 评论 -
Codeforces 204 A (五一训练 A)+想法题
A. Little Elephant and Intervaltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant very much loves s转载 2015-05-07 00:41:09 · 513 阅读 · 0 评论 -
Codeforces Round 313 找规律
题目:Codeforces Round 313560A - Currency System in Geraldion分析:includeusing namespace std;int main(){ int n,a; bool flag; cin>>n; while(n--){ cin>>a; if(a=原创 2015-09-01 19:36:35 · 344 阅读 · 0 评论 -
Codeforces,306DIV.2A. Two Substrings
A. Two Substringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string s. Your task is to determine i原创 2015-07-11 13:09:29 · 382 阅读 · 0 评论 -
Codeforces Round 459 D. Pashmak and Parmida's problem 树状数组求逆序数 变形
D. Pashmak and Parmida's problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputParmida is a clever girl a原创 2015-08-16 16:23:34 · 340 阅读 · 0 评论 -
559B - Equivalent Strings & 560D - Equivalent Strings
D. Equivalent Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday on a lecture about strings Gerald learned原创 2015-09-01 19:29:59 · 1029 阅读 · 0 评论 -
627A - XOR Equation 数学
题目:627A - XOR EquationTwo positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair(a, b)?InputThe first line of the原创 2016-03-15 12:49:50 · 634 阅读 · 0 评论