Codeforces696 Round #362 (Div. 1)(vp) A~D题解
很久没有打比赛了,内部模拟赛天天垫底,第一次vp之旅又是和**一样,这样下去GDOI之后直接退役算了
整场都在忘开LL
A. Lorenzo Von Matterhorn
这个题一看我就想直接虚树+树剖强行搞,但是这个是A题啊。。。写着中途看榜已经100+的人A了,冷静思考发现可以暴力计算每个修改对询问的印影响,用树上差分搞搞,两个点的LCA可以用位运算求,反正心态崩着乱推乱玩各种出锅浪费了1h最后给混过去了,不过还是一个很不错的题
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=3e3+_; struct opera1
{
int t; LL x,w;
opera1(){}opera1(int T,LL X,LL W){t=T,x=X,w=W;}
}a[maxn],b[maxn];int alen,blen;LL as[maxn];
int DEP(LL x)
{
int t=;
while(x>)x/=,t++;
return t-;
}
LL LCA(LL x,LL y)
{
LL u,v;
for(u=x;u!=(u&-u);u-=(u&-u));
for(v=y;v!=(v&-v);v-=(v&-v));
LL ret=;
while(u!=&&v!=)
{
if(((x&u)==)^((y&v)==))break;
ret=(ret<<)|((x&u)?:);
u>>=,v>>=;
}
return ret;
}
int op[maxn];
int main()
{
int n;LL u,v,w;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&op[i]);
if(op[i]==)
{
scanf("%lld%lld%lld",&u,&v,&w);
a[++alen]=opera1(i,u,w);
a[++alen]=opera1(i,v,w);
a[++alen]=opera1(i,LCA(u,v),-*w);
}
else
{
scanf("%lld%lld",&u,&v);
b[++blen]=opera1(i,u,);
b[++blen]=opera1(i,v,);
b[++blen]=opera1(i,LCA(u,v),-);
}
}
for(int i=;i<=alen;i++)
for(int j=;j<=blen;j++)
if(a[i].t<b[j].t)
{
LL lca=LCA(a[i].x,b[j].x);
as[b[j].t]+=DEP(lca)*a[i].w*b[j].w;
}
for(int i=;i<=n;i++)
if(op[i]==)printf("%lld\n",as[i]); return ;
}
A. Lorenzo Von Matterhorn
B. Puzzles
这题是个sb题,先把子树tot搞出来,考虑一个兄弟在我前面被遍历的概率是1/2,直接算就可以了,过的很快
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=1e5+_; struct node
{
int x,y,next;
}a[maxn];int len,last[maxn];
void ins(int x,int y)
{
len++;
a[len].x=x;a[len].y=y;
a[len].next=last[x];last[x]=len;
}
int tot[maxn];double f[maxn];
void dfs(int x)
{
tot[x]=;
for(int k=last[x];k;k=a[k].next)
{
dfs(a[k].y);
tot[x]+=tot[a[k].y];
}
}
void dfs2(int x)
{
for(int k=last[x];k;k=a[k].next)
{
f[a[k].y]=f[x]++(double)(tot[x]--tot[a[k].y])/2.0;
dfs2(a[k].y);
}
} int main()
{
int n,F;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&F),ins(F,i);
dfs();
f[]=;dfs2();
for(int i=;i<n;i++)printf("%.6lf ",f[i]);
printf("%.6lf\n",f[n]); return ;
}
B Puzzles
C.PLEASE
vp的时候看到这个题画了下柿子发现随便转移,分母是2^n,概率矩乘一下很好算,但是分数的形式很乱搞,就先过了,果然是我不会的数论。后来打了一侧和中间的表发现是一个很熟悉的数列x=x+y,y=2*x,对于一侧有fi=fi-1+2*fi-2(见过很多次了,原来这个是Jacobsthal sequence,这个东西一定是个奇数所以就可以分开做了)Jacobsthal sequence的第n项=(2^n-(-1)^n)/3,算出一侧的,推出中间的就好了
注意有个坑,就是数列是乘起来而不是加起来的。。。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL mod=1e9+;
LL quick_pow(LL A,LL p)
{
LL ret=;
while(p!=)
{
if(p%==)ret=ret*A%mod;
A=A*A%mod;p/=;
}
return ret;
}
int main()
{
int n; LL p,a=,b=mod-;
scanf("%d",&n);
while(n--)
{
scanf("%lld",&p);
a=quick_pow(a,p)%mod;
b=quick_pow(b,p)%mod;
}
int z=((a-b+mod)%mod)*quick_pow(,mod-)%mod;
a=a*quick_pow(,mod-)%mod;
printf("%lld/%lld\n",(mod+a-z)%mod,a); return ;
}
C. PLEASE
D. Legen...
这也是一个一眼题,AC机+DP+矩乘优化,但是这个矩乘的运算方式有点诡异(max(cij,aik+bkj))导致在时间内没有调出来,感觉还是惯性思维了,把一个最值题想成计数题
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn=+;
const int maxS=+;
const int maxc=+;
const LL inf=(1LL<<);
int li;
struct Matrix
{
LL mp[maxS][maxS];
void clear(){memset(mp,,sizeof(mp));}
void Mmin(){for(int i=;i<li;i++)for(int j=;j<li;j++)mp[i][j]=-inf;}
friend Matrix operator *(Matrix a,Matrix b)
{
Matrix c;c.Mmin();
for(int i=;i<li;i++)
for(int j=;j<li;j++)
for(int k=;k<li;k++)
if(a.mp[i][k]!=-inf&&b.mp[k][j]!=-inf)
c.mp[i][j]=max(c.mp[i][j],a.mp[i][k]+b.mp[k][j]);
return c;
}
}ans,A;
Matrix quick_pow(Matrix c,Matrix a,LL p)
{
while(p!=)
{
if(p%==)c=c*a;
a=a*a;p/=;
}
return c;
} struct Trie
{
int w[maxc],fail;
LL s;
}tr[maxS];int trlen; char ss[maxS];
void insert(int d)
{
int now=,len=strlen(ss+);
for(int i=;i<=len;i++)
{
int x=ss[i]-'a'+;
if(tr[now].w[x]==)tr[now].w[x]=++trlen;
now=tr[now].w[x];
}
tr[now].s+=d;
}
int head,tail,list[maxS];
void bfs()
{
head=,tail=;list[head]=;
while(head!=tail)
{
int now=list[head];
for(int x=;x<=;x++)
{
int son=tr[now].w[x];
if(son==)continue;
if(now==)tr[son].fail=;
else
{
int pre=tr[now].fail;
while(pre!=&&tr[pre].w[x]==)pre=tr[pre].fail;
tr[son].fail=tr[pre].w[x];
tr[son].s+=tr[tr[son].fail].s;
}
list[tail++]=son;
}
head++;
}
} int a[maxn];
int main()
{
int n;LL L;
scanf("%d%lld",&n,&L);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++)
scanf("%s",ss+),insert(a[i]);
li=trlen+;
bfs(); A.Mmin();
for(int now=;now<=trlen;now++)
for(int x=;x<=;x++)
{
int pre=now;
while(pre!=&&tr[pre].w[x]==)pre=tr[pre].fail;
int son=tr[pre].w[x];
if(son!=)A.mp[now][son]=tr[son].s;
}
ans.Mmin();ans.mp[][]=;
ans=quick_pow(ans,A,L); LL mmax=;
for(int i=;i<=trlen;i++)mmax=max(mmax,ans.mp[][i]);
printf("%lld\n",mmax); return ;
}
D. Legen...
E、F留坑待填
Codeforces696 Round #362 (Div. 1)(vp) A~D题解的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- BestCoder Round #11 (Div. 2) 前三题题解
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...
- Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填
我就做了前两题,第一题第一次vp就把我搞自闭跑路了,第二题第二次又把我搞自闭了 A. As Fast As Possible 细节题 #include<cstdio> #include&l ...
- 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles
期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...
- Codeforces Round #362 (Div. 2) A.B.C
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #362 (Div. 2)->B. Barnicle
B. Barnicle time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #362 (Div. 2)->A. Pineapple Incident
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)
题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...
随机推荐
- java常用组件
一.Jpanel 1.面板:容器类组件 2.用途:与Layout配合使用,JFrame—>JPanel—>Layout 二.JTextField 1.文本框 2.JPasswordFiel ...
- 深入理解Thread构造函数
上一篇快速认识线程 本文参考汪文君著:Java高并发编程详解. 1.线程的命名 在构造现成的时候可以为线程起一个名字.但是我们如果不给线程起名字,那线程会有一个怎样的命名呢? 这里我们看一下Threa ...
- Win7下Nginx的安装与配置
1. 下载nginx1.9.9版本:(版本随时间而变,下载最新即可) http://nginx.org/download/nginx-1.9.9.zip 2. 解压软件到对应位置,并重命名文件夹为n ...
- 8.【nuxt起步】-vue组件之间数据交互
那么现在问题来了,我现在是在index.vue获取了服务端的数据,怎么传值到maincontent.vue?当然你也可以把获取数据放在maincontent.vue,但假如有些数据同时在header, ...
- intellij idea 的常用有用快捷键
ctrl + R:替换(这一点和office 中的ctrl + H不一样) ctrl + alt + L:自动整理代码(不会整理注释文件) ctrl + alt:(自动导入包,不能批量导入,有人评论批 ...
- HttpClient通过Post方式发送Json数据
服务器用的是Springmvc,接口内容: @ResponseBody @RequestMapping(value="/order",method=RequestMethod.PO ...
- 怎样制作gif图片?怎样制作你项目的动态效果图到你的csdn?
怎样制作gif图?怎样上传你项目的动态效果图到你的csdn? 这仅仅是笔者用的方法.有其它方法的欢迎分享. 一张或几张展示了你的项目的功能及效果的动态图放在博客文章开头会为你的文章润色不少. 相信非常 ...
- 【凯子哥带你夯实应用层】使用ActionProvider实现子菜单时遇到的一个坑
转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 近期在重温Android基础.在看到ActionProvider的时候遇到一个坑.分享到大家,避免入坑. 首 ...
- python(12)- 文件处理应用Ⅰ
一.读取文件,打印第三行时后面加入“徐亚平” 程序如下: count=0 with open("test",mode="r",encoding="ut ...
- ORACLE 查看表结构
select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select tabl ...