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操作 ...
随机推荐
- codevs——1700 施工方案第二季
1700 施工方案第二季 2012年市队选拔赛北京 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description c国边防 ...
- 树(弱化版)(lca)
3306: 树 时间限制: 10 Sec 内存限制: 256 MB 题目描述 给定一棵大小为 n 的有根点权树,支持以下操作: • 换根 • 修改点权 • 查询子树最小值 输入 第一行 ...
- Codeforces Gym 100431D Bubble Sort 水题乱搞
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...
- Andriod PopupWindow 键盘冲突
调起键盘的时候,弹出PopupWindow,但是键盘没有隐藏. private void init() { View contentView = LayoutInflater.from(mContex ...
- go 协程与主线程强占运行
最近在学习了Go 语言 , 正好学习到了 协程这一块 ,遇到了困惑的地方.这个是go语言官方文档 . 在我的理解当中是,协程只能在主线程释放时间片后才会经过系统调度来运行协程,其实正确的也确实是这样 ...
- iOS开发 Coretext基本用法
转至 http://blog.csdn.net/fengsh998/article/details/8691823 API接口文档. https://developer.apple.com/libra ...
- 【iOS开发-58】tableView初识:5个重要方法的使用和2种样式的差别
创建一个tableView,直接拖拽放在storyboard里面就可以. (1)先创建一个数据模型类WSCarGroup,在WSCarGroup.h文件里: #import <Foundatio ...
- myBatis-plus异常提示For input string: "{0=null}"
异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...
- CSDN站点系统升级公告
各位尊敬的CSDN用户: 你们好. CSDN站点将于2015年12月17日23时-12月18日08时进行系统升级维护,升级维护期间,CSDN站点将会受到影响.可能会导致博客.下载频道及站点其它功能无法 ...
- hadoop集群搭建datenode为0问题的解决
搭建了一个小的实验集群,一共4台机器,一台namenode,三台datenode.运行start-all,发如今namenode上没有报不论什么错误,可是启动后直接显示datenode数量为0. ...