【Link】:http://codeforces.com/contest/839/problem/C

【Description】



给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是相同的(但不能到你之前到过的点);

问你从1出发走过的路径的期望长度;

【Solution】



从1出发,看看到达某个点的概率是多少;

到了叶子节点的时候,概率乘距离累加到答案上.



【NumberOf WA】



0



【Reviw】

【Code】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define ri(x) scanf("%d",&x)
  14. #define rl(x) scanf("%lld",&x)
  15. #define rs(x) scanf("%s",x+1)
  16. #define oi(x) printf("%d",x)
  17. #define ol(x) printf("%lld",x)
  18. #define oc putchar(' ')
  19. #define os(x) printf(x)
  20. #define all(x) x.begin(),x.end()
  21. #define Open() freopen("F:\\rush.txt","r",stdin)
  22. #define Close() ios::sync_with_stdio(0)
  23. typedef pair<int,int> pii;
  24. typedef pair<LL,LL> pll;
  25. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  26. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  27. const double pi = acos(-1.0);
  28. const int N = 1e5;
  29. int n;
  30. double dp[N+10],ans;
  31. vector <int> G[N+10];
  32. void dfs(int x,int fa,double now,double P){
  33. int len = G[x].size();
  34. if (x!=1 && len==1){
  35. ans += P*now;
  36. return;
  37. }
  38. double p;
  39. if (x==1)
  40. p = 1/(1.0*len);
  41. else
  42. p = 1/(1.0*(len-1));
  43. rep1(i,0,len-1){
  44. int y = G[x][i];
  45. if (y==fa) continue;
  46. dfs(y,x,now+1,P*p);
  47. }
  48. }
  49. int main(){
  50. //Open();
  51. //Close();
  52. ri(n);
  53. rep1(i,1,n-1){
  54. int x,y;
  55. ri(x),ri(y);
  56. G[x].pb(y),G[y].pb(x);
  57. }
  58. dfs(1,0,0,1);
  59. printf("%.13f\n",ans);
  60. return 0;
  61. }

【Codeforces Round #428 (Div. 2) C】Journey的更多相关文章

  1. 【Codeforces Round #428 (Div. 2) B】Game of the Rows

    [Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...

  2. 【Codeforces Round #428 (Div. 2) A】Arya and Bran

    [Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...

  3. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  4. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  5. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  6. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  7. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  8. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  9. 【Codeforces Round #423 (Div. 2) A】Restaurant Tables

    [Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...

随机推荐

  1. Gym - 100203A Ariel 暴力+位运算

    题意:第i种生物有k[i]个特征,分数是score[i],现在要参加竞赛,报出一种生物a,和一些特征h[i],参加竞赛的所有生物在这些h[i]上面的特征是一样的,a生物有h[i],则所有竞赛的生物都必 ...

  2. HDU 5353 Average 贪心

    就是贪心啊,不知道为啥总是不过,总是WA 方法不对吗? 将数组扩展一倍,从左到右扫描,大于平均数就给右边的,小于就从右边拿,等于就不变,记录下操作类型. 大于2直接NO,不知道哪错了,自己出了一些数据 ...

  3. P3908 异或之和

    题目描述 求1 \bigoplus 2 \bigoplus\cdots\bigoplus N1⨁2⨁⋯⨁N 的值. A \bigoplus BA⨁B 即AA , BB 按位异或. 输入输出格式 输入格 ...

  4. modelForm所遇问题

    1. 通过modelForm创建表单所遇问题 id 在modelForm中无法创建使用 因为它是django的设置,自增的字段,而不是模型中所设置的字段. 当关联外键时,创建多选的下拉框时,需要注意此 ...

  5. Swift学习笔记(8)--函数

    1.定义及调用 func sayHelloAgain(personName: String) -> String { return "Hello again, " + per ...

  6. 使用bitmap处理海量数据

    bitmap是一个十分实用的结构.所谓的Bit-map就是用一个bit位来标记某个元素相应的Value, 而Key即是该元素.因为採用了Bit为单位来存储数据,因此在存储空间方面,能够大大节省.  适 ...

  7. HBase概念学习(八)开发一个类twitter系统之表设计

    这边文章先将可能的需求分析一下,设计出HBase表,下一步再開始编写client代码. TwiBase系统 1.背景 为了加深HBase基本概念的学习,參考HBase实战这本书实际动手做了这个样例. ...

  8. 程序猿的量化交易之路(13)--Cointrader类图(1)

    转载须注明出处:http://blog.csdn.net/minimicall? viewmode=contents, htpp://cloudtrader.top 今天開始正式切入到Cointrad ...

  9. Oracle的表空间和sqlplus

    1.  表空间的概念 曾经接触过的数据库都没有听到过表空间这个词,在前一段时间看到Oracle数据库的时候发现表空间无处不在. 所以表空间在Oracle数据库中应该是一个非经常常使用而且非常重要的概念 ...

  10. IsoAlgo3d三维管道软件

    IsoAlgo3d三维管道软件 eryar@163.com 1.概述 IsoAlgo3d三维管道软件主要用于将目前国际主流管道设计软件AVEVA PDMS和Intergraph SmartPlatn3 ...