很久没有打比赛了,内部模拟赛天天垫底,第一次vp之旅又是和**一样,这样下去GDOI之后直接退役算了

整场都在忘开LL

A. Lorenzo Von Matterhorn

这个题一看我就想直接虚树+树剖强行搞,但是这个是A题啊。。。写着中途看榜已经100+的人A了,冷静思考发现可以暴力计算每个修改对询问的印影响,用树上差分搞搞,两个点的LCA可以用位运算求,反正心态崩着乱推乱玩各种出锅浪费了1h最后给混过去了,不过还是一个很不错的题

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. typedef long long LL;
  9. const int _=1e2;
  10. const int maxn=3e3+_;
  11.  
  12. struct opera1
  13. {
  14. int t; LL x,w;
  15. opera1(){}opera1(int T,LL X,LL W){t=T,x=X,w=W;}
  16. }a[maxn],b[maxn];int alen,blen;LL as[maxn];
  17. int DEP(LL x)
  18. {
  19. int t=;
  20. while(x>)x/=,t++;
  21. return t-;
  22. }
  23. LL LCA(LL x,LL y)
  24. {
  25. LL u,v;
  26. for(u=x;u!=(u&-u);u-=(u&-u));
  27. for(v=y;v!=(v&-v);v-=(v&-v));
  28. LL ret=;
  29. while(u!=&&v!=)
  30. {
  31. if(((x&u)==)^((y&v)==))break;
  32. ret=(ret<<)|((x&u)?:);
  33. u>>=,v>>=;
  34. }
  35. return ret;
  36. }
  37. int op[maxn];
  38. int main()
  39. {
  40. int n;LL u,v,w;
  41. scanf("%d",&n);
  42. for(int i=;i<=n;i++)
  43. {
  44. scanf("%d",&op[i]);
  45. if(op[i]==)
  46. {
  47. scanf("%lld%lld%lld",&u,&v,&w);
  48. a[++alen]=opera1(i,u,w);
  49. a[++alen]=opera1(i,v,w);
  50. a[++alen]=opera1(i,LCA(u,v),-*w);
  51. }
  52. else
  53. {
  54. scanf("%lld%lld",&u,&v);
  55. b[++blen]=opera1(i,u,);
  56. b[++blen]=opera1(i,v,);
  57. b[++blen]=opera1(i,LCA(u,v),-);
  58. }
  59. }
  60. for(int i=;i<=alen;i++)
  61. for(int j=;j<=blen;j++)
  62. if(a[i].t<b[j].t)
  63. {
  64. LL lca=LCA(a[i].x,b[j].x);
  65. as[b[j].t]+=DEP(lca)*a[i].w*b[j].w;
  66. }
  67. for(int i=;i<=n;i++)
  68. if(op[i]==)printf("%lld\n",as[i]);
  69.  
  70. return ;
  71. }

A. Lorenzo Von Matterhorn

B. Puzzles

这题是个sb题,先把子树tot搞出来,考虑一个兄弟在我前面被遍历的概率是1/2,直接算就可以了,过的很快

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. typedef long long LL;
  9. const int _=1e2;
  10. const int maxn=1e5+_;
  11.  
  12. struct node
  13. {
  14. int x,y,next;
  15. }a[maxn];int len,last[maxn];
  16. void ins(int x,int y)
  17. {
  18. len++;
  19. a[len].x=x;a[len].y=y;
  20. a[len].next=last[x];last[x]=len;
  21. }
  22. int tot[maxn];double f[maxn];
  23. void dfs(int x)
  24. {
  25. tot[x]=;
  26. for(int k=last[x];k;k=a[k].next)
  27. {
  28. dfs(a[k].y);
  29. tot[x]+=tot[a[k].y];
  30. }
  31. }
  32. void dfs2(int x)
  33. {
  34. for(int k=last[x];k;k=a[k].next)
  35. {
  36. f[a[k].y]=f[x]++(double)(tot[x]--tot[a[k].y])/2.0;
  37. dfs2(a[k].y);
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. int n,F;
  44. scanf("%d",&n);
  45. for(int i=;i<=n;i++)
  46. scanf("%d",&F),ins(F,i);
  47. dfs();
  48. f[]=;dfs2();
  49. for(int i=;i<n;i++)printf("%.6lf ",f[i]);
  50. printf("%.6lf\n",f[n]);
  51.  
  52. return ;
  53. }

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,算出一侧的,推出中间的就好了

注意有个坑,就是数列是乘起来而不是加起来的。。。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. typedef long long LL;
  9. const LL mod=1e9+;
  10. LL quick_pow(LL A,LL p)
  11. {
  12. LL ret=;
  13. while(p!=)
  14. {
  15. if(p%==)ret=ret*A%mod;
  16. A=A*A%mod;p/=;
  17. }
  18. return ret;
  19. }
  20. int main()
  21. {
  22. int n; LL p,a=,b=mod-;
  23. scanf("%d",&n);
  24. while(n--)
  25. {
  26. scanf("%lld",&p);
  27. a=quick_pow(a,p)%mod;
  28. b=quick_pow(b,p)%mod;
  29. }
  30. int z=((a-b+mod)%mod)*quick_pow(,mod-)%mod;
  31. a=a*quick_pow(,mod-)%mod;
  32. printf("%lld/%lld\n",(mod+a-z)%mod,a);
  33.  
  34. return ;
  35. }

C. PLEASE

D. Legen...

这也是一个一眼题,AC机+DP+矩乘优化,但是这个矩乘的运算方式有点诡异(max(cij,aik+bkj))导致在时间内没有调出来,感觉还是惯性思维了,把一个最值题想成计数题

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. typedef long long LL;
  9. const int maxn=+;
  10. const int maxS=+;
  11. const int maxc=+;
  12. const LL inf=(1LL<<);
  13. int li;
  14. struct Matrix
  15. {
  16. LL mp[maxS][maxS];
  17. void clear(){memset(mp,,sizeof(mp));}
  18. void Mmin(){for(int i=;i<li;i++)for(int j=;j<li;j++)mp[i][j]=-inf;}
  19. friend Matrix operator *(Matrix a,Matrix b)
  20. {
  21. Matrix c;c.Mmin();
  22. for(int i=;i<li;i++)
  23. for(int j=;j<li;j++)
  24. for(int k=;k<li;k++)
  25. if(a.mp[i][k]!=-inf&&b.mp[k][j]!=-inf)
  26. c.mp[i][j]=max(c.mp[i][j],a.mp[i][k]+b.mp[k][j]);
  27. return c;
  28. }
  29. }ans,A;
  30. Matrix quick_pow(Matrix c,Matrix a,LL p)
  31. {
  32. while(p!=)
  33. {
  34. if(p%==)c=c*a;
  35. a=a*a;p/=;
  36. }
  37. return c;
  38. }
  39.  
  40. struct Trie
  41. {
  42. int w[maxc],fail;
  43. LL s;
  44. }tr[maxS];int trlen; char ss[maxS];
  45. void insert(int d)
  46. {
  47. int now=,len=strlen(ss+);
  48. for(int i=;i<=len;i++)
  49. {
  50. int x=ss[i]-'a'+;
  51. if(tr[now].w[x]==)tr[now].w[x]=++trlen;
  52. now=tr[now].w[x];
  53. }
  54. tr[now].s+=d;
  55. }
  56. int head,tail,list[maxS];
  57. void bfs()
  58. {
  59. head=,tail=;list[head]=;
  60. while(head!=tail)
  61. {
  62. int now=list[head];
  63. for(int x=;x<=;x++)
  64. {
  65. int son=tr[now].w[x];
  66. if(son==)continue;
  67. if(now==)tr[son].fail=;
  68. else
  69. {
  70. int pre=tr[now].fail;
  71. while(pre!=&&tr[pre].w[x]==)pre=tr[pre].fail;
  72. tr[son].fail=tr[pre].w[x];
  73. tr[son].s+=tr[tr[son].fail].s;
  74. }
  75. list[tail++]=son;
  76. }
  77. head++;
  78. }
  79. }
  80.  
  81. int a[maxn];
  82. int main()
  83. {
  84. int n;LL L;
  85. scanf("%d%lld",&n,&L);
  86. for(int i=;i<=n;i++)scanf("%d",&a[i]);
  87. for(int i=;i<=n;i++)
  88. scanf("%s",ss+),insert(a[i]);
  89. li=trlen+;
  90. bfs();
  91.  
  92. A.Mmin();
  93. for(int now=;now<=trlen;now++)
  94. for(int x=;x<=;x++)
  95. {
  96. int pre=now;
  97. while(pre!=&&tr[pre].w[x]==)pre=tr[pre].fail;
  98. int son=tr[pre].w[x];
  99. if(son!=)A.mp[now][son]=tr[son].s;
  100. }
  101. ans.Mmin();ans.mp[][]=;
  102. ans=quick_pow(ans,A,L);
  103.  
  104. LL mmax=;
  105. for(int i=;i<=trlen;i++)mmax=max(mmax,ans.mp[][i]);
  106. printf("%lld\n",mmax);
  107.  
  108. return ;
  109. }

D. Legen...

E、F留坑待填

Codeforces696 Round #362 (Div. 1)(vp) A~D题解的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  4. Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填

    我就做了前两题,第一题第一次vp就把我搞自闭跑路了,第二题第二次又把我搞自闭了 A. As Fast As Possible 细节题 #include<cstdio> #include&l ...

  5. 【转载】【树形DP】【数学期望】Codeforces Round #362 (Div. 2) D.Puzzles

    期望计算的套路: 1.定义:算出所有测试值的和,除以测试次数. 2.定义:算出所有值出现的概率与其乘积之和. 3.用前一步的期望,加上两者的期望距离,递推出来. 题意: 一个树,dfs遍历子树的顺序是 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)

    题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...

随机推荐

  1. codevs——1700 施工方案第二季

    1700 施工方案第二季 2012年市队选拔赛北京  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description c国边防 ...

  2. 树(弱化版)(lca)

    3306: 树 时间限制: 10 Sec  内存限制: 256 MB 题目描述 给定一棵大小为 n 的有根点权树,支持以下操作:  • 换根  • 修改点权      • 查询子树最小值 输入 第一行 ...

  3. Codeforces Gym 100431D Bubble Sort 水题乱搞

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  4. Andriod PopupWindow 键盘冲突

    调起键盘的时候,弹出PopupWindow,但是键盘没有隐藏. private void init() { View contentView = LayoutInflater.from(mContex ...

  5. go 协程与主线程强占运行

    最近在学习了Go 语言 ,  正好学习到了 协程这一块 ,遇到了困惑的地方.这个是go语言官方文档 . 在我的理解当中是,协程只能在主线程释放时间片后才会经过系统调度来运行协程,其实正确的也确实是这样 ...

  6. iOS开发 Coretext基本用法

    转至 http://blog.csdn.net/fengsh998/article/details/8691823 API接口文档. https://developer.apple.com/libra ...

  7. 【iOS开发-58】tableView初识:5个重要方法的使用和2种样式的差别

    创建一个tableView,直接拖拽放在storyboard里面就可以. (1)先创建一个数据模型类WSCarGroup,在WSCarGroup.h文件里: #import <Foundatio ...

  8. myBatis-plus异常提示For input string: "{0=null}"

    异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...

  9. CSDN站点系统升级公告

    各位尊敬的CSDN用户: 你们好. CSDN站点将于2015年12月17日23时-12月18日08时进行系统升级维护,升级维护期间,CSDN站点将会受到影响.可能会导致博客.下载频道及站点其它功能无法 ...

  10. hadoop集群搭建datenode为0问题的解决

       搭建了一个小的实验集群,一共4台机器,一台namenode,三台datenode.运行start-all,发如今namenode上没有报不论什么错误,可是启动后直接显示datenode数量为0. ...