[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/ ...
随机推荐
- learning at commad AT+CPSI
[Purpose] Learning how to get mobile network info [Eevironment] Shell terminal, base on gcom command ...
- datatime 模块
import datetime # 这个是一个包 里面包含 对时间的处理 对日期的处理datetime.date # 日期相关datetime.time # 时间相关 # 获取当前详细时间print( ...
- bzoj2045
题解: 莫比乌斯反演经典题目 直接套公式好了 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ll ...
- mq(1):简介
1.mq的使用场景 以前的我,一直都没太搞明白,为什么我们那么需要消息队列,直到我看到了网友scienjus.的这个例子. 例子:假设用户在你的软件中注册,服务端收到用户的注册请求后,它会做这些操作: ...
- redis:集群配置
一.redis集群相关 1.概念:redis集群是通过数据分区提供可用性的,这样即使一部分节点失效也可以继续处理请求. 2.原理:集群使用数据分片实现,一个redis集群包括16384个哈希槽,数据库 ...
- 简单选择排序(Simple Selection Sort)
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- bs4 CSS选择器
#https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#find-all #beautifulSoup可以解析HTML ...
- 十六. Python基础(16)--内置函数-2
十六. Python基础(16)--内置函数-2 1 ● 内置函数format() Convert a value to a "formatted" representation. ...
- 4.4 C++虚析构函数
参考:http://www.weixueyuan.net/view/6373.html 总结: 构造函数是不能声明为虚函数的,析构函数可以被声明为虚函数. 将基类的析构函数声明为虚函数之后,派生类的析 ...
- 7 Serial Configuration 理解(二)
*Serial Configuration Mode 串行配置模式分为:Master Serial 和 Slave Serial (如下图)两类: 两者的区别在与CCLK的输入输出方向:主动模式下为输 ...