毕竟是上紫之后的第一场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)的更多相关文章

  1. [Codeforces Round #526 (Div. 2)]

    https://codeforces.com/contest/1084 A题 数据量很小,枚举就行 #include<iostream> #include<cstdio> #i ...

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

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

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

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

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

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

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

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

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

  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. windows下的mysql迁移到linux下

    最近做毕业设计,需要把windows下的mysql移植到linux下 曾经有过在window下移植mysql数据库的经验,只需要把msql的数据文件复制到另一台安装mysql的机器的数据存放位置,然后 ...

  2. 【BZOJ1568】[JSOI2008]Blue Mary开公司 线段树

    [BZOJ1568][JSOI2008]Blue Mary开公司 Description Input 第一行 :一个整数N ,表示方案和询问的总数.  接下来N行,每行开头一个单词“Query”或“P ...

  3. 【BZOJ3437】小P的牧场 斜率优化

    [BZOJ3437]小P的牧场 Description 背景 小P是个特么喜欢玩MC的孩纸... 描述 小P在MC里有n个牧场,自西向东呈一字形排列(自西向东用1…n编号),于是他就烦恼了:为了控制这 ...

  4. shell批量重命令文件脚本

    批量重命名脚步记录,以备用 假如有一批11.txt 12.txt 13,txt 14.txt 15.txt脚步要要重命名为1.txt 2.txt 3.txt .... 脚本如下: #!/bin/bas ...

  5. 动态设置progressBar的进度

    progressDrawable = this.getResources().getDrawable(R.drawable.image); progressDrawable.setBounds(mSe ...

  6. OC开发_Storyboard——AutoLayout

    一.autolayout 自动布局: 1. 设置所有视图框架的三种方法,可以通过代码创建也可以storyboard设置 = 规则 (1 蓝线+约束:(位置) 使用蓝线,根据蓝线拖动控件,只是告诉Xco ...

  7. 输入一个网站地址到网站展现的过程以及APR协议(鬼知道中间经历了什么)

    以前只知道输入一个网站,然后看着返回琳琅满目的内容,其实中间经历的过程和步骤太多了.为了满足好奇心以及学习需要,特查阅了资料将其记录下来以备后续自己复习. 从我在地址栏输入www.zhihu.com ...

  8. vue 缓存的keepalive页面刷新数据

    用到这个的业务场景是这样的: a页面点击新建列表按钮进入到新建的页面b,填写b页面并点击b页面确认添加按钮,把这些数据带到a页面,填充到列表(数组),可以添加多条, 点击这条的时候进入到编辑页面,确认 ...

  9. postgresql----根据现有表创建新表

    除普通的建表语句"create table table_name(columns);"之外,还可以根据现有表快速的创建新表: 一.使用create table ... (like ...

  10. java之面向对象三大特征(封装,继承,多态)

    一.封装 封装是指将对象的状态信息隐藏在对象内部,不允许外部程序直接访问对象内部信息,而是通过该类提供的对外方法进行内部信息的操作和访问. 封装可以达到以下目的: 1)隐藏类的实现细节 2)让使用者只 ...