毕竟是上紫之后的第一场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. ssh-keygen 不是内部或外部命令解决办法!

    在使用 git 的远程仓库的时候,生成秘钥的使用,会遇到ssh-keygen不是内部命令也不是外部命令的问题: 具体解决: 第一步:找到:Git/usr/bin目录下的ssh-keygen.exe(一 ...

  2. [Jenkins] 批量删除构建历史

    Manage Jenkins -> Script Console def jobName = "Some_Job_Name" def maxNumber = 64 Jenki ...

  3. T-SQL数据库备份

    /*1.--得到数据库的文件目录 @dbname 指定要取得目录的数据库名 如果指定的数据不存在,返回安装SQL时设置的默认数据目录 如果指定NULL,则返回默认的SQL备份目录名 */ /*--调用 ...

  4. 自定义Realm解析

    自定义Realm解析---------------------------------------> /* * Copyright 2005-2013 shopxx.net. All right ...

  5. CentOS7.2升级默认yum安装的php版本

    CentOS7.2yum安装php默认版本为5.4,可以升级通过yum安装更高版本 设置yum源 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtat ...

  6. CodeForces 25C(Floyed 最短路)

    F - Roads in Berland Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  7. Eclipse Tomcat插件的使用

    目录 Eclipse Tomcat插件的使用 Eclipse Tomcat插件的使用 我使用的Eclipse版本是:4.6.3 Eclipse已经自带Tomcat插件,不需要再自己进行安装 1.新建T ...

  8. drop user 报错ora-00604

    问题描述: SQL> show user USER is "SYS" SQL> drop user efmis_zhongyang cascade; drop user ...

  9. 修改mysql的字符集和默认存储引擎

    转自:http://blog.csdn.net/wyzxg/article/details/8779682 author:skatetime:2012/05/18 修改mysql的字符集和默认存储引擎 ...

  10. MySQL两大存储引擎:MyISAM和InnoDB

    Mysql有两大常用的存储引擎MyISAM,InnoDB,默认的形式是前者. 两者基本的差别是对事务处理.外键和行级锁的主持上,InnoDB支持事务处理.外键等高级特性,而MyISAM不支持.MyIS ...