感觉对期望也一无所知……(;′⌒`)╮(╯﹏╰)╭

  一直在考虑怎么dp,最后看了题解——竟然是这样的???【震惊】但是看了题解之后,觉得确实很有道理……

  我们可以考虑最后答案的组成,可以分开计算不同的点对于答案的贡献(期望具有线性性)。我们可以把这个染色的过程看做每一个节点均需要被染色,但只有第一个被染色的节点会消耗1点代价。这样我们就可以分别分析每个点对于答案产生贡献的概率,答案即为概率之和。而一个点会对答案产生影响的概率是多少?实际上这只与它到根的链上的节点是相关的,因为只要在染色它的祖先节点之前染色它,它就会对答案产生为1的贡献。

  那么当它和它的祖先均未被染色时,显然有选择任意节点的概率相等,显然有选择它的概率为 \(\frac{1}{dep[u]}\)(如果选择了其他节点,则该节点无法再产生贡献)。于是……这题就做完了。强啊!%%%

#include <bits/stdc++.h>
using namespace std;
#define maxn 200000
#define db double
int n, dep[maxn];
db ans; int read()
{
int x = , k = ;
char c; c = getchar();
while(c < '' || c > '') { if(c == '-') k = -; c = getchar(); }
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * k;
} struct edge
{
int cnp, to[maxn], last[maxn], head[maxn];
edge() { cnp = ; }
void add(int u, int v)
{
to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++;
to[cnp] = u, last[cnp] = head[v], head[v] = cnp ++;
}
}E1; void dfs(int u, int fa)
{
for(int i = E1.head[u]; i; i = E1.last[i])
{
int v = E1.to[i];
if(v == fa) continue;
dep[v] = dep[u] + ; dfs(v, u);
}
} int main()
{
n = read();
for(int i = ; i < n; i ++)
{
int u = read(), v = read();
E1.add(u, v);
}
dep[] = ; dfs(, );
for(int i = ; i <= n; i ++) ans += (1.0 / (db) dep[i]);
printf("%.10lf\n", ans);
return ;
}

【题解】CF#280 C-Game on Tree的更多相关文章

  1. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  2. CF 369C . Valera and Elections tree dfs 好题

    C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament ...

  3. [LeetCode]题解(python):145-Binary Tree Postorder Traversal

    题目来源: https://leetcode.com/problems/binary-tree-postorder-traversal/ 题意分析: 后序遍历一棵树,递归的方法很简单,尝试用非递归的方 ...

  4. [LeetCode]题解(python):144-Binary Tree Preorder Traversal

    题目来源: https://leetcode.com/problems/binary-tree-preorder-traversal/ 题意分析: 前序遍历一棵树,递归的方法很简单.那么非递归的方法呢 ...

  5. [LeetCode]题解(python):124-Binary Tree Maximum Path Sum

    题目来源: https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题意分析: 给定一棵树,找出一个数值最大的路径,起点可以是任意节点或 ...

  6. CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]

    D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...

  7. 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal

    LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...

  8. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  9. 竞赛题解 - [CF 1080D]Olya and magical square

    Olya and magical square - 竞赛题解 借鉴了一下神犇tly的博客QwQ(还是打一下广告) 终于弄懂了 Codeforces 传送门 『题目』(直接上翻译了) 给一个边长为 \( ...

随机推荐

  1. plsql解决中文乱码

    进入 我的电脑,属性,高级,环境变量,添加2项: 1.LANG=zh_CN.GBK 2.NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK

  2. netty之心跳机制

    1.心跳机制,在netty3和netty5上面都有.但是写法有些不一样. 2.心跳机制在服务端和客户端的作用也是不一样的.对于服务端来说:就是定时清除那些因为某种原因在一定时间段内没有做指定操作的客户 ...

  3. 弹性分布式数据集RDD概述

      [Spark]弹性分布式数据集RDD概述 弹性分布数据集RDD RDD(Resilient Distributed Dataset)是Spark的最基本抽象,是对分布式内存的抽象使用,实现了以操作 ...

  4. python 解决url编译

    from urllib import parse s = parse.unquote("%7B%22name%22%3A%22joe%22%2C%22age%22%3A%2223%22%7D ...

  5. typescript语法

    先来讲一讲TypeScript出现的背景 前端javascript的编程思想与后端java面向对象的编程思想有很大的不同,微软公司借鉴了coffeescript语言,继承了很多C#和java的编程思想 ...

  6. 吴裕雄 python 机器学习——混合高斯聚类GMM模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import mixture from sklearn.metrics ...

  7. 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  8. Selenium基础之--01(将浏览器最大化,设置浏览器固定宽、高,操控浏览器前进、后退)

    1,将浏览器最大化 我们知道调用启动的浏览器不是全屏的,这样不会影响脚本的执行,但是有时候会影响我们"观看"脚本的执行. coding=utf-8 from selenium im ...

  9. TPO-12 C2 A problem of the TA's payroll

    TPO-12 C2 A problem of the TA's payroll payroll n. 工资单:在册职工人数:工资名单: paycheck n. 付薪水的支票,薪水 paperwork ...

  10. C 数数位 while循环

    #include <stdio.h> int main(int argc, char **argv) { //定义两个变量  x n 把n初始化 int x; int n=0; //输入x ...