Codeforces Educational Round #42
终于上紫了qaq
算是省选前的一个好消息了吧qaq
值得纪念。4.10-4.11
CF962A Equator(模拟)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
inline char gc(){static char buf[1<<16],*S,*T;if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}return *S++;
}
inline int read(){int x=0,f=1;char ch=gc();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();return x*f;
}
int n,a[N];ll sum=0,tmp=0;
int main(){
// freopen("a.in","r",stdin);n=read();for(int i=1;i<=n;++i) a[i]=read(),sum+=a[i];for(int i=1;i<=n;++i){tmp+=a[i];if(tmp*2>=sum){printf("%d\n",i);return 0;}}
}
CF962B Students in Railway Carriage(贪心)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,a,b,ans=0,last=0;
char s[N];
int main(){
// freopen("a.in","r",stdin);n=read();a=read();b=read();scanf("%s",s+1);for(int i=1;i<=n;++i){if(s[i]=='*'){last=0;continue;}if(!a&&!b) break;if(last==1){if(b) --b,last=2,++ans;else last=0;continue;}if(last==2){if(a) --a,last=1,++ans;else last=0;continue;}if(a>b) --a,last=1,++ans;else --b,last=2,++ans;}printf("%d\n",ans);return 0;
}
CF962C Make a Square(爆搜)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,ans=inf,bin[11],a[15],m=0;
char s[15];
void dfs(int x){if(x==n+1){if(!m) return;int res=0;for(int i=1;i<=m;++i) res=res*10+a[i];int xx=sqrt(res);if(xx*xx==res) ans=min(ans,n-m);return;}dfs(x+1);if(s[x]=='0'&&!m) return;a[++m]=s[x]-'0';dfs(x+1);--m;
}
int main(){
// freopen("a.in","r",stdin);scanf("%s",s+1);n=strlen(s+1);dfs(1);if(ans==inf) puts("-1");else printf("%d\n",ans);return 0;
}
CF962D Merge Equals(stl)
其实就按输入顺序合并就好了qaq,开个map即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 150010
inline char gc(){static char buf[1<<16],*S,*T;if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}return *S++;
}
inline int read(){int x=0,f=1;char ch=gc();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();return x*f;
}
int n,m;ll a[N];
map<ll,int>mp;
int main(){
// freopen("a.in","r",stdin);n=read();m=n;for(int i=1;i<=n;++i){ll x=read();while(1){int y=mp[x];if(!y) break;--m;a[y]=0;mp[x]=0;x<<=1;}mp[x]=i;a[i]=x;}printf("%d\n",m);for(int i=1;i<=n;++i){if(a[i]) printf("%I64d ",a[i]);}return 0;
}
CF962E Byteland, Berland and Disputed Cities(贪心)
我们把同属两方的点称为红点。
我们考虑任意两个相邻的红点,他们之间的白点黑点怎么连。
对于所有白点,我们肯定是贪心地链接最近的一个白点/红点。
黑点同理。然后我们还可以把两个红点连起来,以节省一条白的和一条黑的,贪心取最优即可。
然后还要处理一下开头一段。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
int n,last1=0,last2=0,last0=0;
ll ans=0,a[N];
int main(){
// freopen("a.in","r",stdin);n=read();ll mx1=0,mx2=0;for(int i=1;i<=n;++i){a[i]=read();char op[5];scanf("%s",op+1);if(op[1]=='P'){if(!last0){if(last1) ans+=a[i]-a[last1];if(last2) ans+=a[i]-a[last2];}else{mx1=max(mx1,a[i]-a[last1]);ans+=a[i]-a[last1];mx2=max(mx2,a[i]-a[last2]);ans+=a[i]-a[last2];if(mx1+mx2>a[i]-a[last0]) ans+=a[i]-a[last0]-mx1-mx2;}last1=last2=last0=i;mx1=0;mx2=0;}if(op[1]=='B'){if(last1) mx1=max(mx1,a[i]-a[last1]),ans+=a[i]-a[last1];last1=i;}else{if(last2) mx2=max(mx2,a[i]-a[last2]),ans+=a[i]-a[last2];last2=i;}}printf("%I64d\n",ans);return 0;
}
Codeforces Educational Round #42相关推荐
- Codeforces Educational Round 5
Codeforces Educational Round 5 通过数: 4 Standing: 196/4176 题目链接: http://codeforces.com/contest/616 A: ...
- Codeforces Educational round 58
Ediv2 58 随手AK.jpg D 裸的虚树,在这里就不写了 E 傻逼贪心?这个题过的比$B$都多.jpg #include <cstdio> #include <algorit ...
- Codeforces Educational Round#21 F(808F) Solution:网络流(最小割)
题意:给出一组卡牌(100张),卡牌有三个属性值:power,c,level,其中c和level是用来限制的,power是目标值. 具体的限制规则是:只有level小于等于玩家的playerlevel ...
- A、B、C、D、Educational Codeforces Round 42 (Rated for Div. 2)
Educational Codeforces Round 42 (Rated for Div. 2) http://codeforces.com/contest/962 A:Equator 这里需要 ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)
题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...
- Codeforces Beta Round #4 (Div. 2 Only)
Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...
- Codeforces Beta Round #7
Codeforces Beta Round #7 http://codeforces.com/contest/7 A 水题 1 #include<bits/stdc++.h> 2 usin ...
- Codeforces Global Round 1 晕阙记
Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...
最新文章
- [20180412]订阅+镜像切换
- C++中 list容器的用法
- Android软键盘隐藏,遮挡EidtText解决办法
- OpenStack Neutron浅析(二)
- java 树状数组模板源码
- python用import xlwt出现红字_如何用python处理excel
- java matcher group_JAVA正则表达式matcher.find()和 matcher.matches()的区别
- Python机器学习:PCA与梯度上升001什么是PCA
- java 局部变量空间 大小_变量作用域-1:局部变量 和成员变量、各种变量内存分配的大小...
- c语言作业答案运行成功图片,桂林电子科技大学 C语言 程序设计 习题 答案(周信东) 实验1 C程序的运行环境和最简单的C程序设计...
- [bzoj1062] [NOI2008]糖果雨
- python lxml 模块_Python lxml模块安装教程
- Python爬虫实战01 ---- 百度贴吧一键签到
- 一键拼接所有微信好友头像
- OC Extension Color(颜色宏定义)
- 创造与魔法怎么自建服务器,创造与魔法如何建立部落 部落建造条件
- 什么样的互联网创业者不靠谱?
- mysql root误删_mysql 误删root
- gym100676 [小熊骑士限定]2015 ACM Arabella Collegiate Programming Contest
- 启明星辰携手联想云 共建企业云服务新生态