Codeforces Round #526 (Div. 1)
毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了。
A. The Fair Nut and the Best Path
这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有150了。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
int to[Maxn],nxt[Maxn],first[Maxn],tot=1;
int n,u,v;
ll a[Maxn],ans,w[Maxn],wi;
queue<int>q;
inline void add(int u,int v,ll wi) {
to[tot]=v;
nxt[tot]=first[u];
w[tot]=wi;
first[u]=tot++;
to[tot]=u;
nxt[tot]=first[v];
w[tot]=wi;
first[v]=tot++;
}
ll dfs(int root,int fa) {
ll mx=0,cd=0,sxz=a[root];
for(int i=first[root];i;i=nxt[i])
if(to[i]!=fa) {
ll temp=dfs(to[i],root)-w[i];
if(temp>mx) cd=mx,mx=temp;
else cd=max(cd,temp);
}
sxz+=mx;
ans=max(ans,sxz+cd);
return sxz;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%I64d",&a[i]);
for(int i=1;i<n;i++) {
scanf("%d%d%I64d",&u,&v,&wi);
add(u,v,wi);
}
dfs(1,1);
printf("%I64d\n",ans);
return 0;
}
B - The Fair Nut and Strings
这道题开始时看上去很毒瘤,但是仔细一想会发现这里面有个树的结构,具体讲不太明白,自己看看代码就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
int n,k;
char a[Maxn],s[Maxn];
int main() {
scanf("%d%d",&n,&k);
scanf("%s",a);
scanf("%s",s);
if(k==1||strcmp(a,s)==0) {
printf("%d\n",n);
return 0;
}
int temp=0;ll sxz=2,ans=0;
while(a[temp]==s[temp]) temp++;ans+=temp;ans+=2;
for(int i=temp+1;i<n;i++) {
sxz<<=1;
if(a[i]=='b') sxz--;
if(s[i]=='a') sxz--;
if(sxz>=k) {
ans+=1ll*(n-i)*k;
break;
}
ans+=sxz;
}
printf("%I64d\n",ans);
return 0;
}
还是自己太菜啊。。
Codeforces Round #526 (Div. 1)的更多相关文章
- [Codeforces Round #526 (Div. 2)]
https://codeforces.com/contest/1084 A题 数据量很小,枚举就行 #include<iostream> #include<cstdio> #i ...
- 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. 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/ ...
随机推荐
- Sencha中Element的使用
在sencha touch中如果你要是用模板来构造一些UI,那么你就必定要去操作Element,如下是我对Element的一些操作和遇到的问题 获取Elenent Ext.get("ID&q ...
- Android 仿微信朋友圈发动态功能(相册图片多选)
代码分享 代码名称: 仿微信朋友圈发动态功能(相册图片多选) 代码描述: 仿微信朋友圈发动态功能(相册图片多选) 代码托管地址: http://www.apkbus.com/android-15276 ...
- 问答项目---用户注册的那些事儿(PHP验证)
JS 验证之后,还需要通过PHP验证: 提交过来的名称不一样,可以用字段映射: 在自动验证的时候,如果这个字段被映射,那么自动验证的时候,自动验证的就是 映射过后的字段: 控制器示例: //注册表单处 ...
- Web安全开发建议
版权声明:原创作品,如需转载,请与作者联系.否则将追究法律责任. Web安全问题,很多时候会被人所忽略,安全漏洞造成了很多不必要的维护和开发任务,产生的问题有时候更是致命的. 实际上,只要我们养成一些 ...
- Oracle归档文件夹权限设置错误导致的数据库问题解决
把oracle设置为归档模式并且为归档文件新建文件夹 /home/oracle/app/oracle/arch/orcl 但是在启动或者备份时候经常性出现错误 startup报错 startup同时日 ...
- opencv学习笔记——Scalar数据结构的理解
首先看一下Scalar的定义 typedef struct Scalar { ]; }Scalar; 可以看到,Scalar是一个由长度为4的数组作为元素构成的结构体,Scalar最多可以存储四个值, ...
- SpringBoot项目属性配置
如果使用IDEA创建Springboot项目,默认会在resource目录下创建application.properties文件,在SpringBoot项目中,也可以使用yml类型的配置文件代替pro ...
- 清空messages方法
1.du -sh /var/log/messages 2.losf /var/log/messages 3.cat /dev/null > /var/log/messages 4.du -sh ...
- django-mvc
而对于真实开发中的python web程序来说,一般会分为两部分:服务器程序和应用程序.服务器程序负责对socket服务器进行封装,并在请求到来时,对请求的各种数据进行整理.应用程序则负责具体的逻辑处 ...
- 什么是虚拟DOM?
(摘抄自一篇文章,觉得这里写得非常不错,所以单独放出来,希望能对大家有帮助.)React为啥这么大?因为它实现了一个虚拟DOM(Virtual DOM).虚拟DOM是干什么的?这就要从浏览器本身讲起 ...