[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/ ...
随机推荐
- 蓝桥杯—BASIC-21 sine之舞(递归递推)
题目:最近FJ为他的奶牛们开设了数学分析课,FJ知道若要学好这门课,必须有一个好的三角函数,所以他准备和奶牛们做一个“Sine之舞”的游戏,寓教于乐,提高奶牛们的计算能力. 不妨设 An=sin(1– ...
- 【oracle常见错误】ora-00119和ora-00132问题的解决方法
oracle11g安装后,本地无法登录!前提:服务全部打开,监听也配置好了! win7 64位 oracle 11g 简单的sql命令: 先登录到sqlplus:sqlplus/nolog; 登录数据 ...
- 如何快速成为一名Linux运维工程师
如今的互联网,绝大多数的网站.服务.游戏均是跑在Linux上面的,虽说Linux发行版众多,只要玩熟了一种发行版,了解了Linux精髓.基本架构.设计原理,其他都是触类旁通的,千万不要在选择哪一发行版 ...
- DBProxy 读写分离使用说明
美团点评DBProxy读写分离使用说明 目的 因为业务架构上需要实现读写分离,刚好前段时间美团点评开源了在360Atlas基础上开发的读写分离中间件DBProxy,关于其介绍在官方文档已经有很详细 ...
- flask项目结构(四)使用sqlalchemy和alembic
简介 其实我不是啥正经人,错了,不是啥正经程序员,所能想到的估计也就码农一级吧,高级程序员,搞什么算法,什么人工智能,大数据计算…………离我还太遥远. 但是这并不妨碍我继续学习,继续写垃圾小程序. 反 ...
- .net core 在扩展中使用接口实例之IServiceProvider
在.net core 2.0中,我们使用的对象实例大多数都是通过构造函数依赖注入进来的,但那是在一般的类中使用. 如果需要在静态/扩展类中使用某些服务类的对象实例,可以使用如下方式: 1.新建一个Se ...
- 生成器 Generators
function* quips(name) { yield "你好 " + name + "!"; yield "希望你能喜欢这篇介绍ES6的译文&q ...
- Android : 输入设备键值从底层到应用层的映射流程
一.Android输入子系统简介: Android输入事件的源头是位于/dev/input/下的设备节点,而输入系统的终点是由WMS管理的某个窗口.最初的输入事件为内核生成的原始事件,而最终交付给窗口 ...
- SharePoint REST API - 列表和列表项
博客地址:http://blog.csdn.net/FoxDave 本篇主要讲述如何用SharePoint REST操作列表和列表项.阅读本篇时请先了解前面讲述的REST介绍和基本操作. 废话不多 ...
- 代码改变世界 | 如何封装一个简单的 Koa
下面给大家带来:封装一个简单的 Koa Koa 是基于 Node.js 平台的下一代 web 开发框架 Koa 是一个新的 web 框架,可以快速而愉快地编写服务端应用程序,本文将跟大家一起学习:封装 ...