毕竟是上紫之后的第一场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. LeetCode——Pascal's Triangle II

    Description: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3 ...

  2. DOM操作的性能问题

    造成DOM操作性能差的原因:1.DOM操作的实现和ECMAscript的实现是两个独立的部分,之间通过接口来完成相应的DOM操作. 2.实时查询文档得到HTML集合,重复执行查询操作.特别是lengt ...

  3. 使用openssl生成RSA公钥和私钥对

    在ubuntu上要使用openssl的话需要先进行安装,命令如下: sudo apt-get install openssl 安装完成就可以使用openssl了. 首先需要进入openssl的交互界面 ...

  4. tomcat配置JMX

    最近看JDK的命令行工具,使用Java VisualVM和Jconsole工具都可以监控java程序的运行情况(包括CUP和内存等的使用情况,线程的运行状态等) 在Java VisualVM 工具里可 ...

  5. Python语音合成

    注意:通过win32com调用的windows的SAPI,所以本脚本只适应于windows平台 代码很简单 #coding:utf-8 import win32com.client import ti ...

  6. 在linux下安装Avria(小红伞)

    1.下载AntiVir PersonalEdition Classic for linux http://www.free-av.com/ 2.解压: tar zxvf antivir.tar.gz ...

  7. 二维坐标系极角排序的应用(POJ1696)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3170   Accepted: 2029 Descrip ...

  8. 使用MySQLMTOP监控MySQL性能(二)

    一.服务器角色 服务器角色 172.18.35.29 10.160.22.14 (MySQL Master) 10.160.22.47 (MySQL Slave) 监控点 YES NO NO 被监控点 ...

  9. CodeForces 19B Checkout Assistant

    B. Checkout Assistant time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.

    Spring Framework Overview https://www.tutorialspoint.com/spring/spring_overview.htm Aspect Oriented ...