洛谷P4316 绿豆蛙的归宿
2024-10-11 07:28:41
一眼看去,这不是高斯消元吗?
然后发现数据范围是100000...
然后发现是DAG...直接拓扑序递推即可。
边(x, y,z)的贡献是P(x) * z / out[x]
#include <cstdio>
#include <queue>
const int N = ; struct Edge {
int v, nex, len;
}edge[N << ]; int top; int in[N], topo[N], e[N], n, out[N];
double p[N]; inline void add(int x, int y, int z) {
top++;
edge[top].v = y;
edge[top].len = z;
edge[top].nex = e[x];
e[x] = top;
return;
} inline void topo_sort() {
std::queue<int> Q;
for(int i = ; i <= n; i++) {
if(!in[i]) {
Q.push(i);
}
}
int t = ;
while(!Q.empty()) {
int x = Q.front();
Q.pop();
topo[++t] = x;
for(int i = e[x]; i; i = edge[i].nex) {
int y = edge[i].v;
in[y]--;
if(!in[y]) {
Q.push(y);
}
}
}
return;
} int main() {
int m;
scanf("%d%d", &n, &m);
for(int i = , x, y, z; i <= m; i++) {
scanf("%d%d%d", &x, &y, &z);
add(x, y, z);
in[y]++;
out[x]++;
}
topo_sort();
p[] = 1.0;
double ans = 0.0;
for(int a = ; a <= n; a++) {
int x = topo[a];
for(int i = e[x]; i; i = edge[i].nex) {
int y = edge[i].v;
p[y] += p[x] / out[x];
ans += p[x] * edge[i].len / out[x];
}
}
printf("%.2lf", ans);
return ;
}
AC代码
最新文章
- web app开发利器 - iscroll4 解决方案
- C#基础-out与ref字段
- 团队作业-第一周-NABCD竞争性需求分析
- 去除手机端a标签等按下去背景色
- jiulianhuan 快速幂--矩阵快速幂
- day3 python 集合 文件
- linux源代码阅读笔记 free_page_tables()分析
- JAVA生成PDF文件
- spring中@param和mybatis中@param使用区别
- 从free命令看Linux内存管理
- (转)syslog日志等级
- c# RSA加密和解密
- 重新学习一次javascript;
- iOS开发之--UIImageView的animationImages动画
- 解决在IDEA 的Maven下 出现 Cannot access in offline mode 问题
- html5 canvas多个图像旋转
- python 爬虫 爬取序列博客文章列表
- Spring Security自定义GrantedAuthority前缀
- AIDL旅行记之开篇AIDL基本介绍
- warning: ignoring option PermSize=256m; support was removed in 8.0
热门文章
- Day 6-1计算机网络基础&;TCP/IP
- 使用 idea 产生错误The server time zone value &#39;&#214;&#208;&#185;&#250;&#177;&#234;&#215;&#188;&#202;&#177;&#188;&#228;&#39; is unrecognized
- python爬虫scrapy的LinkExtractor
- 规范化Normalization
- SQL 添加索引
- jQuery 操作input select,checkbox
- PHP——emjoin表情存入数据库
- C# int数组转string字符串
- D. Flood Fill 区间DP 或lcs匹配
- 「Splay」区间翻转