ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ABC266 - E,F Solutions

2022-09-08 22:05:48  阅读:228  来源: 互联网

标签:rd int lo Vertex ABC266 simple game Solutions


目录

ABC266 - E,F Solutions

E - Throwing the Die

Problem Statement

Let us play a game using a die. The game consists of at most \(N\) turns, each of which goes as follows.

  • Throw a \(6\)-sided die that shows \(1,\ldots,6\) with equal probability, and let \(X\) be the number shown (each throw is independent of the others).
  • If it is the \(N\)-th turn now, your score is \(X\), and the game ends.
  • Otherwise, choose whether to continue or end the game.
    • If you end the game, your score is \(X\), and there is no more turn.

Find the expected value of your score when you play the game to maximize this expected value.

Constraints

  • \(1≤N≤100\)

Solution

一句话题意:投骰子,投出1~6的概率相等,不满意可以重投,最多投n次,期望投出点数是多少?

先考虑 \(N=2\),每次骰子期望投出 \(3.5\) 的分数,于是第一次投出 \(1\text ~3\) 的时候就可以重投。同理,对于更普遍的情况,当第 \(i\) 次投出的结果小于 \(i+1\text ~N\) 计算得到期望时,就可以考虑重投。

Implementation

此处 f[n] 是倒序的。

n=rd();
f[1]=3.50;
jk(i,2,n)jk(j,1,6)f[i]+=std::max((double)j,f[i-1])/6.0;
printf("%.7lf\n",f[n]);

F - Well-defined Path Queries on a Namori

Problem Statement

You are given a connected simple undirected graph \(G\) with \(N\) vertices numbered \(1\) to \(N\) and \(N\) edges. The \(i\)-th edge connects Vertex \(u_i\) and Vertex \(v_i\) bidirectionally.

Answer the following \(Q\) queries.

  • Determine whether there is a unique simple path from Vertex \(x_i\) to Vertex \(y_i\) (a simple path is a path without repetition of vertices).

Constraints

  • \(3≤N≤2×10^5\)
  • \(G\) is a connected simple undirected graph with \(N\) vertices and \(N\) edges.
  • 1 \leq Q \leq 2 \times 10^5

Solution

N点N边,一眼基环树,先tarjan找到环。不难发现两点仅存在一条路径时,它们在环上节点的同一颗(向环外的)子树内,于是直接dfs就好了,下面是样例2的示意图:

Implementation

void ta(int u,int f){
    st[++s]=u;is[u]=1;
    fn[u]=lo[u]=++T;
    for(int i=h[u];i;i=e[i].n){
        int v=e[i].v;
        if(v==f)continue;
        if(!fn[v]){
            ta(v,u);
            lo[u]=std::min(lo[u],lo[v]);
        }else lo[u]=std::min(lo[u],fn[v]);
    }
    Z[lo[u]]++;
}

void df(int u,int f,int b){
    B[u]=b;
    for(int i=h[u];i;i=e[i].n){
        int v=e[i].v;
        if(v!=f&&(u!=b||lo[v]!=o)&&!B[v])df(v,u,b);
    }
}

// puts(B[rd()]^B[rd()]?"No":"Yes");

标签:rd,int,lo,Vertex,ABC266,simple,game,Solutions
来源: https://www.cnblogs.com/choimoe/p/ABC266.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有