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. 深入理解 Java 虚拟机——走近 Java

    1.1 - 概述 Java 总述:Java 不仅是一门编程语言,还是一个由一系列 计算机软件 和 规范 形成的技术体系,这个技术体系提供了完整的用于软件开发和跨平台部署的支持环境,并广泛应用于 嵌入式 ...

  2. nginx:负载均衡(三)分流策略

    [1]轮询策略.轮询策略是最简单的策略,无脑配置,不考虑服务器的访问的能力.每个请求按照时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除 upstream www.daysn. ...

  3. Turing equation

    Turing equation 时间限制: 1 Sec 内存限制: 128 MB 题目描述 The fight goes on, whether to store numbers starting w ...

  4. 7.7 C++基本关联式容器

    参考:http://www.weixueyuan.net/view/6404.html 总结: 基本的关联式容器主要有:set.multiset.map和multimap,这四种容器可以分为两组:ma ...

  5. form 表单模板

    <div class="modal-dialog modal-lg"> //大布局modal-lg <div class="modal-content& ...

  6. 自定义String

    // ShStringNew.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #inclu ...

  7. adb shell按键操作(input keyevent)

    前言:input keyeven操作发送手机上常用的一些按键操作 一.keyevent事件对应数字 电话键 KEYCODE_CALL: 拨号键 KEYCODE_ENDCALL: 挂机键 KEYCODE ...

  8. ob_gzhandler — ob_start callback function to gzip output buffer

    <?php ob_start("ob_gzhandler"); ?><html><body><p>This should be a  ...

  9. ajax参考增删改查

    AJAX做增删改查详细!   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  10. 移动端开发rem单位

    1.用js计算 <script> (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientat ...