【Codeforces Round #428 (Div. 2) C】Journey
【Link】:http://codeforces.com/contest/839/problem/C
【Description】
给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是相同的(但不能到你之前到过的点);
问你从1出发走过的路径的期望长度;
【Solution】
从1出发,看看到达某个点的概率是多少;
到了叶子节点的时候,概率乘距离累加到答案上.
【NumberOf WA】
0
【Reviw】
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;
int n;
double dp[N+10],ans;
vector <int> G[N+10];
void dfs(int x,int fa,double now,double P){
int len = G[x].size();
if (x!=1 && len==1){
ans += P*now;
return;
}
double p;
if (x==1)
p = 1/(1.0*len);
else
p = 1/(1.0*(len-1));
rep1(i,0,len-1){
int y = G[x][i];
if (y==fa) continue;
dfs(y,x,now+1,P*p);
}
}
int main(){
//Open();
//Close();
ri(n);
rep1(i,1,n-1){
int x,y;
ri(x),ri(y);
G[x].pb(y),G[y].pb(x);
}
dfs(1,0,0,1);
printf("%.13f\n",ans);
return 0;
}
【Codeforces Round #428 (Div. 2) C】Journey的更多相关文章
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 【Codeforces Round #428 (Div. 2) A】Arya and Bran
[Link]: [Description] [Solution] 傻逼题 [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> usi ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- Linux Unix shell 编程指南学习笔记(第五部分)
第二十五章 深入讨论 << 当shell 看到 << 的时候,它知道下一个词是一个分界符.该分界符后面的内容都被当做输入,直到shell又看到该分界符(位于单独的一行).比方: ...
- 123.static静态函数与类模板
#include <iostream> using namespace std; //静态函数没有this指针,无需创建对象就可以直接调用 template<class T> ...
- useradd
功能说明:useradd命令可用于创建新的用户或者更改用户的信息. 语法格式:useradd [选项] [用户名]useradd -D [选项] 选项说明:1.使用useradd常规添加用户工作原理流 ...
- Debian9 ifconfig命令找不到解决办法
Debian9 ifconfig命令找不到解决办法 ifconfig.route.arp和netstat等命令行工具(它们统称为net-tools),管理和排查各种网络配置.这类工具原先起源于BSD ...
- ES6学习笔记(三)字符串的扩展
ES6 加强了对 Unicode 的支持,并且扩展了字符串对象. 1.字符的Unicode表示法 JavaScript 允许采用\uxxxx形式表示一个字符,其中xxxx表示字符的 Unicode 码 ...
- angular实现简单的pagination分页组件
不想使用第三方库,只想使用一个分页器,那么就简单的实现一个,效果如下: 1.使用方式: <custom-pagination *ngIf="enterpriseList.length& ...
- SimpleDateFormat 时间格式化
- SSL通关之代码演示样例(四)
实际开发过程中,server端是不须要多加代码处理的,由于ssl验证过程是由server(tomcat.nginx等)完毕的. 这段代码也是參考了网上的: 新建一个web项目,项目结构和须要引入的ja ...
- .Net视图机制
.Net会有默认的约定. HomeController下面的Index,会默认渲染Home/Index.cshtml. 当然可以设置成别的,比如设置成About. using System; usin ...
- amaze ui响应式表格
amaze ui响应式表格 这里的div外嵌设置格式倒是不错的选择