[Codeforces Round #526 (Div. 2)]
https://codeforces.com/contest/1084
A题
数据量很小,枚举就行
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int qwq[];
int main(){
// freopen("in.txt","r",stdin);
int n;
cin>>n;
for(int i=;i<=n;i++){
scanf("%d",&qwq[i]);
}
int ans=0x3f3f3f3f;
for(int i=;i<=n;i++){
int xx=;
for(int j=;j<=n;j++){
xx+=*(abs(j-i)+(i-)+(j-))*qwq[j];
}
ans=min(xx,ans);
}
cout << ans<<endl;
return ;
}
B题
二分,只要不犯sb错就行(然而我犯sb错fst了 #微笑#)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll qwq[],n,k;
bool check(ll x){
ll sums=;
for(int i=;i<n;i++){
if(qwq[i]<x)return false;
else sums+=qwq[i]-x;
} if(sums>=k)return true;
return false;
}
int main(){
// freopen("in.txt","r",stdin);
//ll n,k;
cin>>n>>k;
ll sum=;
for(int i=;i<n;i++){
scanf("%lld",&qwq[i]);
sum+=qwq[i];
}
if(sum<k){printf("-1\n");return ;}
ll l=;
ll r=1e9+;
while(l<=r){
ll mid=(l+r)/;
if(check(mid))l=mid+;
else r=mid-;
}
while(check(l+))l++;
while(!check(l))l--;
cout << l << endl;
return ;
}
C题
题意:给一个字符串,求有多少个子序列满足:元素都为a,并且如果元素个数>1,那么在原序列中每个a之间必须至少有一个b.
题解:无视除a,b之外的别的字母,用b把a分成若干部分,设第i部分的a的个数是 ai ,那么这个部分的取法有 (ai+1)种(即不取,或者从中选一个)但是最后要防止所有部分不取,即ans=(a1+1)*(a2+1)*,,,*(ax+1) -1 .
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
char ch[];
int qwq[],qaq[];
ll mypow(ll x,ll y){
ll ans=;
while(y){
if(y&)ans=(ans%mod)*(x%mod)%mod;
x=(x%mod)*(x%mod)%mod;
y/=;
}
return ans;
}
int main(){
//freopen("in.txt","r",stdin);
scanf("%s",ch);
int len=strlen(ch);
ll tot=;
ll tot2=;
ll tot3=;
ll tot4=;
ll ans=;
for(int i=;i<len;i++){
if(ch[i]=='a'){if(tot3){qaq[tot4]=tot3;tot3=;tot4++;}tot2++;}
else if(ch[i]=='b'){
if(tot2){
qwq[tot]=tot2;
tot2=;
tot++;
}
if(tot)tot3++;
}
}if(tot2)qwq[tot++]=tot2;
for(int i=;i<tot;i++){
ans=(ans%mod)*((qwq[i]+)%mod)%mod;
}
cout << ans-<<endl;
return ;
}
D题
题意:给一棵树,求一条链顶点的权值和 - 边的权值和的最大值
题解:开两个dp数组,一个数组记录从根出发到当前结点得到的最大值,另一个数组记录从该点遍历到尽头回溯得到的最大值(这就很好的解决了到底应该从哪个点开始dfs的问题..因为一边递归过程dp,一边回溯过程dp可以确保得到的一定是最优解)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll ans=;
int head[];
ll qwq[];
struct edge{
int u;
int v;
ll val;
int nex;
}e[];
int cnt;
ll dp[],dp2[];
bool vis[];
void add(int x,int y,ll z){
e[cnt].u=x;
e[cnt].v=y;
e[cnt].val=z;
e[cnt].nex=head[x];
head[x]=cnt++;
}
void dfs(int x){
vis[x]=;
for(int i=head[x];i!=-;i=e[i].nex){
int v=e[i].v;
if(vis[v])continue;
dp[v]=max(qwq[v],qwq[v]+dp[x]-e[i].val);
dfs(v);
dp2[x]=max(dp2[x],dp2[v]+qwq[x]-e[i].val);
dp[x]=max(dp2[x],dp[x]);
}
dp2[x]=max(dp2[x],qwq[x]);
dp[x]=max(dp[x],dp2[x]);
ans=max(dp[x],ans);
}
int main(){
// freopen("in.txt","r",stdin);
cin>>n;
for(int i=;i<=n;i++){
scanf("%lld",&qwq[i]);
}
memset(head,-,sizeof(head));
for(int i=;i<n-;i++){
int a,b;
ll c;
scanf("%d%d%lld",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dfs();
printf("%lld\n",ans);
return ;
}
[Codeforces Round #526 (Div. 2)]的更多相关文章
- Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings
E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path
D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...
- Codeforces Round #526 (Div. 2) C. The Fair Nut and String
C. The Fair Nut and String 题目链接:https://codeforces.com/contest/1084/problem/C 题意: 给出一个字符串,找出都为a的子序列( ...
- Codeforces Round #526 (Div. 2) A.B
A. The Fair Nut and Elevator 题目链接:https://codeforces.com/contest/1084/problem/A 题意: 一栋房子有n层楼,同时有个电梯( ...
- Codeforces Round #526 Div. 1 自闭记
日常猝死. A:f[i]表示子树内包含根且可以继续向上延伸的路径的最大价值,统计答案考虑合并两条路径即可. #include<iostream> #include<cstdio> ...
- Codeforces Round #526 (Div. 2) Solution
A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...
- Codeforces Round #526 (Div. 1)
毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp
D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...
- A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))
A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...
随机推荐
- ubuntu16.10安装搜狗输入法
一.搜狗输入法安装 1.首先到搜狗输入法官网下载搜狗输入法,下载的是个deb文件. 搜狗输入法Linux版下载地址:http://pinyin.sogou.com/linux/?r=pinyin 2. ...
- AI工具(矩形工具)(椭圆工具的操作与矩形类似)(剪切蒙版)5.11
矩形工具:按住SHIFT键,可以绘制一个正方形. 按住ALT键,可以绘制以落点为中心的矩形. 同时按住SHIFT和ALT键可以绘制以鼠标落点为中心的正方形. 选择矩形工具,点击页面,输入高宽,精确绘制 ...
- owin启动事项
在上下文中找不到 owin.Environment 项 owin没有启动. 尝试加载应用时出现了以下错误.- 找不到包含 OwinStartupAttribute 的程序集 startup类不是通过v ...
- isScroll 插件在iPhone 5s 和以上版本
才加入这个移动项目组三天,解决一个同事(请假),解决一个切换头部tab 选型时,下拉数据,再次切换到另外一个选项时,出现滚动条距离顶部有些距离,当频繁操作会出现距离顶部距离加大问题(第二天衍生出其他b ...
- zookeeper:shell操作以及可视化工具的使用
1.zkcli.sh基本使用 1-1 查看节点 进入zk的bin目录下执行./zkCli.sh ls命令可以查看节点,/zookeeper/quota是默认的节点 1-2新增节点 create key ...
- 自己写了一个解析json为table的工具类
还需要完善的包括,css的封装,触发事件,数据的获得处理: <!DOCTYPE html> <html> <head> <meta charset=" ...
- 【阿圆实验】Grafana HA高可用方案
一.实现Grafana高可用 1.Grafana实现高可用性有两步: >>使用共享数据库存储仪表板,用户和其他持久数据>>决定如何存储会话数据. 2.Grafana高可用部署图 ...
- linux命令学习 随笔
linux命令随笔 linux命令随笔 用户操作 搜索命令 PATH环境变量 Linux中的通配符 文件搜索命令locate 搜索命令的命令whereis与which 文件搜索命令find(最强大的哦 ...
- angular2架构详解
参考 http://codin.im/2016/09/18/angular2-architecture-intro/ http://www.tuicool.com/articles/EvEZjmZ ...
- Unity3d代码及效率优化总结
1.PC平台的话保持场景中显示的顶点数少于200K~3M,移动设备的话少于10W,一切取决于你的目标GPU与CPU. 2.如果你用U3D自带的SHADER,在表现不差的情况下选择Mobile或Unli ...