codeforces
fa茶
这个作者很懒,什么都没留下…
展开
-
Codeforces Round #258 (Div. 2)——B. Sort the Array
B. Sort the Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBeing a programmer, you like arrays a lot.原创 2014-07-25 08:39:18 · 1089 阅读 · 0 评论 -
Codeforces Round #292 (Div. 2)E. Drazil and Park——线段树
http://codeforces.com/contest/515/problem/E具体解释看这个http://blog.csdn.net/u013654696/article/details/43898869每个节点维护3个域 A[rt]=2*h[l]+d[l-1] B[rt]=2*h[l]-d[l-1] s[rt]=max energy 其中d[l]表示1到l的距离 将环变为线性的1原创 2015-02-25 14:33:19 · 1043 阅读 · 0 评论 -
Codeforces Round #293 (Div. 2)D.Ilya and Escalator——概率dp
http://codeforces.com/contest/518/problem/Ddp[i][j] 表示第i秒有j个人进入电梯的概率#include<bits/stdc++.h>const int maxn=2100;using namespace std;double dp[maxn][maxn];int n,t;double p;int main(){#ifndef ONLI原创 2015-03-14 21:30:00 · 403 阅读 · 0 评论 -
Codeforces Round #296 (Div. 2)——A.B.C.D
http://codeforces.com/contest/527A. Playing with Paper给一张矩形的纸,每次对折成一个正方形,然后对剩下的矩形重复操作,求最多可以获得多少个矩形#include<bits/stdc++.h>#define ll long longusing namespace std;ll a,b;int main(){ scanf("%I64d原创 2015-03-20 20:17:42 · 673 阅读 · 0 评论 -
Codeforces Round #294 (Div. 2)——C.D
http://codeforces.com/contest/519/problem/C#include<bits/stdc++.h>using namespace std;int n,m;int main(){//#ifndef ONLINE_JUDGE//freopen("in.cpp","r",stdin);//#endif // ONLINE_JUDGE scanf("%d原创 2015-03-10 13:16:03 · 460 阅读 · 0 评论 -
Codeforces Round #295 (Div. 2)C - DNA Alignment——规律
转http://blog.csdn.net/codebattle/article/details/4402210315 ms 108 KB#include<bits/stdc++.h>#define ll long longconst int maxn=100005;const int mod=1e9+7;using namespace std;int n;char s[maxn];原创 2015-03-09 23:54:26 · 472 阅读 · 0 评论 -
Codeforces Round #297 (Div. 2)——A.B.C.D.E
http://codeforces.com/contest/525A. Vitaliy and Pie 从左到右模拟一下#include<bits/stdc++.h>const int MAXN=200100;using namespace std;string s;int n;int key[MAXN];int main(){ scanf("%d",&n); cin原创 2015-03-29 12:04:43 · 654 阅读 · 0 评论 -
Codeforces Round #298 (Div. 2)——A.B.C.D.E
http://codeforces.com/contest/534A. Exam#include<bits/stdc++.h>using namespace std;int main(){ int n; scanf("%d",&n); if(n<=2){ printf("1\n1\n"); } else if(n==3){原创 2015-04-15 14:38:21 · 455 阅读 · 0 评论 -
Codeforces Round #299 (Div. 2)——A.B.C.D
http://codeforces.com/contest/535A. Tavas and Nafas 题目描述:给你0~99的数字,输出它的英文表示法#include<bits/stdc++.h>using namespace std;char* s[100]={"zero","one","two","three","four","five","six","seven","eight","原创 2015-04-27 16:48:29 · 590 阅读 · 0 评论 -
Codeforces Round #300——A.B.C.D.E.F
http://codeforces.com/contest/538A. Cutting Banner 题目描述: 给你一个字符串,判断能否通过删除其中的某一个连续的字串,得到“CODEFORCES”这个字符串#include<bits/stdc++.h>using namespace std;int main(){ string cf="CODEFORCES"; strin原创 2015-05-05 19:17:40 · 1013 阅读 · 0 评论 -
Codeforces Round #301 (Div. 2)——A.B.C.D.E
A. Combination Lock 有两种旋转方式#include <bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; string s1,s2; cin>>s1>>s2; int ans=0; int a,b; for(int i=0;i<n;++i){原创 2015-05-13 12:09:56 · 352 阅读 · 0 评论 -
Codeforces Round #305 (Div. 2)——D
http://codeforces.com/contest/548/problem/DD. Mike and Feet 一个长度为n的序列,在长度为x的子序列中取最小值,所有中取最大值。 for x = 1 to ndp[i]表示以i为最小值的最长区间长度 g[i]表示区间长度为i时的最大值 sum[i]表示区间长度大于等于i的最大值那么对于某个询问x,答案为sum[x]单调栈搞dp[i],原创 2015-05-27 15:53:57 · 763 阅读 · 0 评论 -
Codeforces Round #304 (Div. 2)——A.B.C.D.E
http://codeforces.com/contest/546A. Soldier and Bananas 去超市买东西,第一个东西k元,第二个东西2*k元。问要借多少钱#include <bits/stdc++.h>#define LL long long#define foreach(v,i) for(__typeof((v).begin()) i=(v).begin();i!=(v)原创 2015-05-26 23:54:15 · 665 阅读 · 0 评论 -
Codeforces Round #302 (Div. 2)——A.B.C.D.E
http://codeforces.com/contest/544A. Set of Strings 把一个串分成n个子串,要求这几个子串的第一个字母互不相同#include <bits/stdc++.h>using namespace std;int main(){#ifndef ONLINE_JUDGEfreopen("in.cpp","r",stdin);#endif // ON原创 2015-05-19 00:04:49 · 631 阅读 · 0 评论 -
Codeforces Round #291 (Div. 2)E. Darth Vader and Tree——dp+矩阵快速幂
http://codeforces.com/contest/514/problem/E原创 2015-02-22 19:26:58 · 635 阅读 · 0 评论 -
Codeforces Round #291 (Div. 2)D.R2D2 and Droid Army——RMQ+二分
http://codeforces.com/contest/514n个机器人,每个机器人有m个属性,有k发子弹,每发子弹可以使所有机器人的某个属性减一。当某个机器人的m个属性都变为0时,该机器人视为被摧毁。 求在某段连续区间内消灭机器人数目最多的条件下,机器人的每个属性所需要的子弹数先二分枚举最长的连续区间,然后根据所得的区间长度,求出某个可行解#include<bits/stdc++.h>#d原创 2015-02-21 22:50:32 · 522 阅读 · 0 评论 -
Codeforces Round #223 (Div. 2)——A. Sereja and Dima
A. Sereja and Dimatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja and Dima play a game. The rules of原创 2014-08-04 08:26:24 · 653 阅读 · 0 评论 -
Codeforces Round #223 (Div. 2)——B. Sereja and Stairs
B. Sereja and Stairstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja loves integer sequences very muc原创 2014-08-04 08:21:07 · 931 阅读 · 0 评论 -
Codeforces Round #224 (Div. 2) A. Ksenia and Pan Scales
A. Ksenia and Pan Scalestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKsenia has ordinary pan scales and原创 2014-08-05 20:48:11 · 654 阅读 · 0 评论 -
CodeForces Round #288 Div.2. E-Arthur and Brackets——dp/greedy
CodeForces Round #288 Div.2有一些配好对的括号,现在已知第i对括号,左右括号的距离在[Li, Ri]区间中。按照左括号出现的顺序编号。输出原括号序列。greedy:只有前一个括号匹配完,后一个括号才能匹配。所以前一个括号今早的匹配,后一个括号才有更多的机会匹配如果当前左括号在p位置,则右括号所在的区间为[L[i]+p,R[i]+p]原创 2015-01-29 16:36:07 · 539 阅读 · 0 评论 -
Codeforces Round #288 (Div. 2)C. Anya and Ghosts(模拟+贪心)
Anya因为很喜欢看鬼片,所以鬼要来她家做客。每个鬼到来的时候必须要有k根蜡烛亮着。Anya点亮一根蜡烛要一秒,每根蜡烛持续m秒,问她最少要几根蜡烛1.如果蜡烛的持续时间小于鬼来需要的蜡烛,则不能成功2.每次都在鬼来的前一秒钟开始点蜡烛,用优先队列模拟,如果队列中元素个数小于需要的蜡烛,则添加蜡烛;如果对头元素小于鬼来的时间减去蜡烛持续的时间,说明这根蜡烛已经熄灭了,就把它出队。每原创 2015-01-28 21:11:49 · 486 阅读 · 0 评论 -
Codeforces Round #288 (Div. 2)D.Tanya and Password——欧拉通路
Codeforces Round #288 (Div. 2)给出n个长度为3的字符串,求由这些字符串组成的长度为n+2的字符串,要求前后缀有两个相同的字符构图:例如abc,那么ab——bc在搜索过程中,前面跟后面已经搜过的不必再搜。有向图判断是否存在欧拉通路,并输出路径#include#define ONLINE_JUDGEconst int max原创 2015-01-30 19:22:48 · 397 阅读 · 0 评论 -
Codeforces Round #289 (Div. 2, ACM ICPC Rules)E.Pretty Song
Codeforces Round #289 (Div. 2, ACM ICPC Rules)求一个字符串的所有字串的权值和,每个字串的权值为元音字母的个数比上字串的长度将字串转化为01串,那么区间[l,r]的字串的权值为(s[r]-s[l-1])/(r-l+1),枚举长度k,则所有字串的权值和为Sigma(1/k *(s[k]-[s0] + s[k+1]-s[1]+...s[n]-s[原创 2015-02-03 16:34:05 · 579 阅读 · 0 评论 -
Codeforces Round #289 (Div. 2, ACM ICPC Rules)C. Sums of Digits——贪心+模拟
Codeforces Round #289 (Div. 2, ACM ICPC Rules)给你一个数b[i],求出各个位上数字和为b[i]的数a[i],要求所有数字是递增的法1:1.b[i]-b[i-1]>0 ,那么从最低位开始加1,直到得到所求的数2.else,从最低位开始累加差值,直到差值为正的,转1法2:纯模拟,有个优化,位数为j的数,各个位上数原创 2015-02-04 17:11:42 · 456 阅读 · 0 评论 -
CF div.2B. Mr. Kitayuta's Colorful Graph
给你一张图,求顶点u到v有多少种颜色的路径判断连通性:floyd,并查集,dfs,bfs先枚举颜色,然后判断这种颜色的路径是否存在#include#include#include#define rep(i,a,b) for(int i=a;i<b;++i)#define repd(i,a,b) for(int i=a;i<=b;++i)#define mes(s,c)原创 2015-01-19 16:36:50 · 482 阅读 · 0 评论 -
Codeforces Round #290 (Div. 2)E. Fox And Dinner——最大流 奇偶建图
http://codeforces.com/contest/510/problem/En只狐狸要吃饭,要求每张桌子至少3只狐狸,相邻两只狐狸的年龄和是素数因为年龄至少为2,所以和为素数一定是奇数,奇数=奇数 偶数,超级源点0对所有的奇数连一条边,cap=2,所有的偶数和超级汇点连一条边,cap=2.如果某个奇数和某个偶数和为素数,则连一条边,cap=1. 有解当且仅当最大流为n#include<b原创 2015-02-08 23:07:06 · 440 阅读 · 0 评论 -
Codeforces Round #290 (Div. 2)B - Fox And Two Dots——并查集/搜索
http://codeforces.com/contest/510/problem/B给你一张地图,判断是否存在一个圈我的劣质代码#include<bits/stdc .h>using namespace std;int n,m;char mp[55][55];int vis[55][55];int dirx[]={0,0,1,-1};int diry[]={1,-1,0,0};b原创 2015-02-07 15:37:19 · 471 阅读 · 0 评论 -
Codeforces Round #290 (Div. 2)C - Fox And Names——拓扑排序
http://codeforces.com/contest/510/problem/C给你n个字符串,求是否存在按所给的字符串的顺序能够得到一个新的a-z的顺序表拓扑排序 注意点:上下相邻两个串,如果上面的串是下面的串的前缀,则无需重新排列,反之如果下面的串是上面的串的前缀,则输出impossible。否则,就对相邻两个串最左边第一个不相同的字母之间连一条有向边输出合法的a-z的序列#includ原创 2015-02-07 15:23:25 · 531 阅读 · 0 评论 -
Codeforces Round #290 (Div. 2)D - Fox And Jumping——数论gcd=1
http://codeforces.com/contest/510/problem/D给你n个卡片和每个卡片的花费,求用最少的花费使得用所买的卡片可以到达任意的位置只要所取的卡片的最大公约数为1就可以到达任意的位置,贪心维护最小值,最后结果为mp[1]#include<bits/stdc .h>using namespace std;int n;int l[310],c[310];map<原创 2015-02-07 15:29:49 · 689 阅读 · 0 评论 -
Codeforces Round #291 (Div. 2)C.Watto and Mechanism——字典树+dfs
http://codeforces.com/contest/514n个字符串m个询问,判断询问的字符串能否通过修改其中的一个字符使得变成给定的n个字符串中的某一个注意:必须修改一个字符#include<bits/stdc++.h>const int maxnode=6e5+100;const int sigma_size=3;using namespace std;int n,m;int原创 2015-02-20 21:29:47 · 831 阅读 · 0 评论 -
Codeforces Round #303 (Div. 2)——A.B.C.D.E
http://codeforces.com/contest/545好水的一场div2. A. Toy Cars a[i][j] = 1,表示第i辆车坏掉了,=2 表示第j辆车坏掉了,=3表示i和j都坏掉了。求有几辆车是好的#include <bits/stdc++.h>#define foreach(v,i) for(__typeof((v).begin()) i=(v).begin();i!原创 2015-05-22 14:50:04 · 806 阅读 · 0 评论