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. docker 部署 java 项目

    Docker Docker官方网址: https://docs.docker.com/  英文地址 Docker中文网址: http://www.docker.org.cn/ 中文地址 Docker是 ...

  2. HTML的语义化和一些简单优化

    1.什么是语义化? 必应网典的解释 语义化是指用合理HTML标记以及其特有的属性去格式化文档内容.通俗地讲,语义化就是对数据和信息进行处理,使得机器可以理解. 语义化的(X)HTML文档有助于提升你的 ...

  3. NFS共享权限挂载

    mount -t nfs 192.168.2.203:/data/lys /lys -o proto=tcp -o nolock mount 172.16.2.18:/home/arcgisserve ...

  4. ionic入门

    ionic安装 Ionic开发是依赖于Nodejs环境的,所以在开发之前我们需要安装好Nodejs.下载安装:http://nodejs.org/安装完成之后打开PowerShell输入命令node ...

  5. Python中识别DataFrame中的nan

    # 识别python中DataFrame中的nanfor i in pfsj.index: if type(pfsj.loc[i]['WZML']) == float: print('float va ...

  6. [20180124]奇怪的SQL*Net message from dblink.txt

    [20180124]奇怪的SQL*Net message from dblink.txt --//生产系统出现大量的SQL*Net message from dblink事件,自己分析看看. 1.环境 ...

  7. [20170617]vim中调用sqlplus.txt

    [20170617]vim中调用sqlplus.txt --//以前写过一篇emacs下调用sqlplus的文章,一直想学emacs,受限制自己掌握vim,对学习它没有兴趣,原链接如下:--//htt ...

  8. linq Distinct 自定义去重字段

    一.定义 1.Falcon_PumpX_Equal_Comparer :类名,随便取名 2.IEqualityComparer:必须继承这个接口 3.Falcon_PumpX:需要去重的对象 4.IE ...

  9. 第五章 绘图基础(LINEDEMO)

    LINEDEMO程序绘制一个矩形.两条直线.一个椭圆和一个圆角矩形.该程序表明,定义了封闭矩形的这些函数确实对这些区域进行了填充,因为椭圆后面的线被隐藏了. /*------------------- ...

  10. [SequenceFile_3] MapFile

    0. 说明 MapFile 介绍 && 测试 1. 介绍 对 MapFile 的介绍如下: MapFile 是带有索引的 SequenceFile MapFile 是排序的 Seque ...