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)]的更多相关文章

  1. 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的 ...

  2. 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 题意: 给出一棵树,走不重复的 ...

  3. 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的子序列( ...

  4. Codeforces Round #526 (Div. 2) A.B

    A. The Fair Nut and Elevator 题目链接:https://codeforces.com/contest/1084/problem/A 题意: 一栋房子有n层楼,同时有个电梯( ...

  5. Codeforces Round #526 Div. 1 自闭记

    日常猝死. A:f[i]表示子树内包含根且可以继续向上延伸的路径的最大价值,统计答案考虑合并两条路径即可. #include<iostream> #include<cstdio> ...

  6. Codeforces Round #526 (Div. 2) Solution

    A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...

  7. Codeforces Round #526 (Div. 1)

    毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...

  8. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp

    D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...

  9. A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))

    A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...

随机推荐

  1. jquery radio使用

    var list= $('input:radio[name="list"]:checked').val();

  2. ASP.Net MVC(1) 之走进MVC

    一.MVC三层架构: mvc三层架构,大家都比较熟悉了,这里再介绍一下.Mvc将应用程序分离为三个部分: Model:是一组类,用来描述被处理的数据,同时也定义这些数据如何被变更和操作的业务规则.与数 ...

  3. Mybatis之trim标签的理解

    最近在学Mybatis,在学到动态sql的trim标签时,很迷惑.不知所以然.看别人的博客和论坛里的解释,太宽泛,还是不能理解: trim元素的主要功能是可以在自己包含的内容前加上某些前缀,也可以在其 ...

  4. JavaScript -基础- 函数与对象(二)String

    一.判断数据类型typeof与判断对象类型instanceof 1.typeof typeof只能判断基础数据类型,无法判断引用数据类型 <script> var s="hell ...

  5. Python Django 之 直接执行自定义SQL语句(一)

    一.执行自定义SQL方法 1.Executing custom SQL directly      直接执行自定义SQL,这种方式可以完全避免数据模型,而是直接执行原始的SQL语句. 2.Manage ...

  6. ActiveMQ的P2P示例

    ActiveMQ的P2P示例(点对点通信) (1)下载安装activemq,启动activeMQ. 详细步骤参考博客:http://www.cnblogs.com/DFX339/p/9050878.h ...

  7. 主机访问虚拟机centos7的服务器

    一.虚拟机开启桥梁接 1.编辑-->虚拟网络编辑器 2.虚拟机-->设置 二.Centos的配置---关闭防火墙下的服务器接口 Centos7.0 默认使用firewall作为防火墙,这里 ...

  8. 深入理解java虚拟机---Class文件(二十)

    无符号数.表 当实现了不同语言的编译器,比如jython,jruby等等,那么就可以利用这些语言编写代码,通过各自的编译器编译成符合jvm规范的字节码文件,就可以利用jvm来执行了. Class文件在 ...

  9. 线程安全的集合类、CopyOnWrite机制介绍(转)

    看过并发编程的书,这两种机制都有所了解,但不扎实其实.看到别人的博客描述的很精辟,于是转过来,感谢! 原文链接:https://blog.csdn.net/yen_csdn/article/detai ...

  10. HDU 2063 (二分图最大匹配)

    RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每个女孩 ...