Div1 526

  • 这个E考试的时候没调出来真的是耻辱.jpg

A

求个直径就完事

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
#define ll long long
struct miku
{
int to,next,val;
}e[600010];
int a[300010];
int head[300010];
int cnt;
int n;
ll ans;
ll f[300010];
void add(int x,int y,int z)
{
e[cnt]=(miku){y,head[x],z};
head[x]=cnt++;
}
void dfs(int x,int from)
{
f[x]=a[x];
ans=max(ans,(ll)a[x]);
for(int i=head[x];i!=-1;i=e[i].next)
{
int to1=e[i].to;
if(to1!=from)
{
dfs(to1,x);
ans=max(ans,f[x]+f[to1]-e[i].val);
f[x]=max(f[x],f[to1]+a[x]-e[i].val);
}
}
}
int main()
{
scanf("%d",&n);
memset(head,-1,sizeof(head));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1,x,y,z;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
dfs(1,0);
printf("%lld\n",ans);
}

B

可以发现,最优答案显然是能劈叉就劈叉...

然后这还是个特判题,有一些边界条件需要处理清楚...

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 500005
#define ll long long
char s[N],t[N];
ll ans;
int n,k,now,tmp;
int main()
{
scanf("%d%d%s%s",&n,&k,s+1,t+1);s[n+1]='#';
if(k==1)return printf("%d\n",n),0;
for(now=1;s[now]==t[now];now++);
if(now>n)return printf("%d\n",n),0;ans=now+1;
for(int i=now+1;i<=n;i++)
{
tmp=tmp<<1;
if(s[i]=='a')tmp++;
if(t[i]=='b')tmp++;
tmp=min(k-2,tmp);
ans+=tmp+2;
}
printf("%lld\n",ans);
}//

C

  • 打死我也不会写的
  • (极有可能真香

一看就知道是个傻逼题。

线段树维护值域,然后就是求出$l,r$这段的链长啥样就行...

然后判断这俩链是否能转化为同一个链...

D

$O(n^2)$枚举+验证就可以了...

然后可以想到维护处$L_i$和$R_i$表示$i$这个数左边第一个和它一样的,和右边第一个和它一样的...

然后考虑以$i$为结尾的答案是什么,$ans=\sum\limits_{j=1}[i,j]\times (j-\max{ L_{j...i}})\times(\min{R_{j...i}}-i)$,$[i,j]$表示,$i...j$满足要求

那么考虑$[i,j]$可以直接在枚举$i$的时候维护出来,$L_j$和$R_j$也可以在同时用单调栈维护出来,那么上面这个式子可以拆成$4$个部分,分别在线段树上再维护一下就好了...

代码没有

E

傻逼斜率优化!

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 1000005
#define ll long long
struct node{ll x,y,val;}a[N];
int sta[N],top,n;
ll f[N],ans;
inline bool cmp(const node &a,const node &b){return a.x==b.x?a.y<b.y:a.x<b.x;}
#define K(i) (a[i].x)
#define B(i) (f[i])
#define Y(i,j) (-K(i)*a[j].y+B(i)) bool cmp1(int i,int j,int k)
{
long double x=(long double)(K(i)-K(k))*(B(j)-B(i));
long double y=(long double)(K(i)-K(j))*(B(k)-B(i));
return x>=y;
} int find(int x)
{
int l=0,r=top;
while(l<r)
{
int m=(l+r)>>1;
if(Y(sta[m],x)<Y(sta[m+1],x))l=m+1;
else r=m;
}return sta[l];
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].val);
sort(a+1,a+n+1,cmp);a[0].x=0,a[0].y=1<<30;
for(int i=1;i<=n;i++)
{
int p=find(i);
f[i]=f[p]+(a[i].x-a[p].x)*a[i].y-a[i].val;ans=max(ans,f[i]);
while(top>=1&&cmp1(i,sta[top-1],sta[top]))top--;
sta[++top]=i;
}
printf("%lld\n",ans);
}

F

是个根号算法,就算了.jpg

Codeforces round 1083的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. CSS中的行内元素和块级元素

    我们在构造页面时,会发现有的元素是上下排列的,而有的则是横向排列的,这是为啥子呢   看看上图,我们也没给他设置啥子属性咋就不一样了,其实是因为每个元素都有默认的 display 属性,比如 div ...

  2. Spark机器学习——模型选择与参数调优之交叉验证

    spark 模型选择与超参调优 机器学习可以简单的归纳为 通过数据训练y = f(x) 的过程,因此定义完训练模型之后,就需要考虑如何选择最终我们认为最优的模型. 如何选择最优的模型,就是本篇的主要内 ...

  3. loadrunner11中文版破解文档+录制脚本(图/文)

    下面是整理后的loadrunner11破解版的所有文件及操作步骤. LoadRunner11安装 1.Loadrunner11下载链接:https://pan.baidu.com/s/15Svt3kt ...

  4. Expo大作战(四十)--expo sdk api之 Calendar,Constants

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  5. PHP LAMP环境搭建及网站配置流程(完整版)

    心血来潮想做一个自己的博客网站,写一些文章做技术分享,平时遇到的一些问题的解决办法都记录下来,网站搭建成功,那么第一篇博客自然就是整个网站的搭建以及域名的注册.备案.解析流程,总共分为以下几步: 1. ...

  6. 利用java webservice调用天气预报实践

    最近要和其他业务系统进行数据交换,选择了webservice方案,于是查了一下网上的用法.首先是做一个天气的查询例子,看着挺简单,可实际动手做起来发现坑很多,费了半天劲终于调通了,于是记录下来. 1, ...

  7. Ubuntu18.04 安装tomcat9

    1.官网下载 2.移动到/usr/local/tomcat 3.解压 4.修改权限,否则在idea中不能正常使用

  8. web机试

    测试: <html><style> </style><title>Demo</title> <body><div > ...

  9. Java面试题以及答案精选(架构师面试题)-基础题1

    基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...

  10. (16)Python练习题

    练习题一: 练习题二: