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/ ...
随机推荐
- Android 7.1 SystemUI--任务管理--场景一:长按某个缩略图,拖动分屏的流程
TaskView 类的长按事件 onLongClick 方法内发送了 DragStartEvent 事件消息,该 DragStartEvent 事件消息由 RecentsView,TaskStackV ...
- 3149: [Ctsc2013]复原
3149: [Ctsc2013]复原 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 95 Solved: 44[ ...
- [黑金原创教程] FPGA那些事儿《数学篇》- CORDIC 算法
简介 一本为完善<设计篇>的书,教你CORDIC算法以及定点数等,内容请看目录. 贴士 这本教程难度略高,请先用<时序篇>垫底. 目录 Experiment 01:认识CORD ...
- Egret打包App Android热更新(4.1.0)
官网教程:http://developer.egret.com/cn/github/egret-docs/Native/native/hotUpdate/index.html 详细可看官网教程,我这里 ...
- 【BZOJ3012】[Usaco2012 Dec]First! Trie树+拓补排序
[BZOJ3012][Usaco2012 Dec]First! Description Bessie has been playing with strings again. She found th ...
- 【BZOJ1030】[JSOI2007]文本生成器 AC自动机+动态规划
[BZOJ1030][JSOI2007]文本生成器 Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文 ...
- 双调欧几里得旅行商问题(TSPhdu2224)
http://acm.hdu.edu.cn/showproblem.php?pid=2224 The shortest path Time Limit: 1000/1000 MS (Java/Othe ...
- 使用webmagic搭建一个简单的爬虫
刚刚接触爬虫,听说webmagic很不错,于是就了解了一下. webmagic的是一个无须配置.便于二次开发的爬虫框架,它提供简单灵活的API,只需少量代码即可实现一个爬虫. 这句话说的真的一点都不假 ...
- 使用 Sonar 进行代码质量管理
参考资料: 使用 Sonar 进行代码质量管理 SonarQube的安装.配置与使用 SonarLint(Sonar) 代码质量管理
- Day27-28 基础加强
day28基础加强 今日内容 泛型 注解 Servlet3.0 动态代理 类加载器 泛型 回顾泛型类 泛型类:具有一个或多个泛型变量的类被称之为泛型类. public class A<T&g ...