【Codeforces 696B】Another Sith Tournament &【JZOJ 4647】寻找

使用 Python 爬虫获取中国证券市场公司公告数据 本文详细介绍了如何使用 Python 爬虫技术从中国证券市场(如巨潮资讯网)爬取公司公告数据。通过分析网页结构,编写爬虫脚本,抓取并存储公告信息,我们实现了从网页抓取数据的全过程。此外,本文还展示了如何应对反爬虫机制,并介绍了数据分析与可视化的基本方法。未来,我们可以通过机器学习等技术进一步挖掘公告中的潜在信息,例如,通过情感分析对公告内容进行情绪分类,或者预测某些公告类型对股市走势的影响等。希望本文能帮助你理解如何使用 Python 爬虫技术获取和处理证券市场的数据,并为你的数据分析项目提供帮助。 阅读详情

Description

Codeforces

Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney’s not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads.

Some girl has stolen Barney’s heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows:

let starting_time be an array of length n

current_time = 0
dfs(v):
    current_time = current_time + 1
    starting_time[v] = current_time
    shuffle children[v] randomly (each permutation with equal possibility)
    // children[v] is vector of children cities of city v
    for u in children[v]:
        dfs(u)

As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)).

Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city i, Barney wants to know the expected value of starting_time[i]. He’s a friend of Jon Snow and knows nothing, that’s why he asked for your help.

Input
The first line of input contains a single integer n(1 ≤ n ≤ 105) — the number of cities in USC.

The second line contains n - 1 integers p2, p3, ..., pn(1 ≤ pi < i), where pi is the number of the parent city of city number i in the tree, meaning there is a road between cities numbered pi and i in USC.

JZOJ

Bob和Alice出去度蜜月,但Alice不慎走失,Bob在伤心过后,决定前去寻找Alice。
他们度蜜月的地方是一棵树,共有N个节点,Bob会使用下列DFS算法对该树进行遍历。

starting_time是一个容量为n的数组
current_time = 0
dfs(v):        
       current_time = current_time + 1        
       starting_time[v] = current_time        
       将children[v]的顺序随机排列 (每个排列的概率相同)        
       // children[v]v的直接儿子组成的数组        
       for u in children[v]:               

1是这棵树的根,Bob会从1出发,即运行dfs(1),现在他想知道每个点starting_time的期望值。

Solution

期望值=概率*权值,

设每个子树的总点数为sii,祖先f有h个儿子,对于f的每一个儿子s,每一轮走到它的概率都是1h(就是在走它之前无论做了多少个其他点),
第一轮走就直接走,
第二轮走,那么在走它之前的增加的期望步数就是siq−sish−1,
第三轮就是把除了点s以外的所有的sison的两两组合,也就是=C1h−2C2h−1∗(siq−sis)=2h−1∗(siq−sis),(把原公式拆开来分开来写即可发现),
第四轮同理,为:=C2h−2C3h−1∗(siq−sis)=3h−1∗(siq−sis),
…..
所以,对于每个点s,走到它之前增加的期望值就是:

(siq−sis)∗∑i=1h−1in

化简一下:
siq−sis2

最后预处理以后直接扫一遍即可。
复杂度:O(n);

Code

#include<cstdio> 
#include<cstdlib>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define iff() if(B[i][1]!=fa)
using namespace std;
typedef double db;
const int N=100500;
int read(int &n)
{
    char ch=' ';int q=0,w=1;
    for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
    if(ch=='-')w=-1,ch=getchar();
    for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int n;
int B[N][2],A[N],B0;
int b[N],b1[N];
db ans[N];
void link(int q,int w){B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;}
int dfs1(int q,int fa)
{
    b[q]=1;
    efo(i,q)iff()b[q]+=dfs1(B[i][1],q),b1[q]++;
    return b[q];
}
void dfs2(int q,db s,int fa)
{
    ans[q]=++s;db s1=0.5;
    efo(i,q)iff()dfs2(B[i][1],s+(b[q]-b[B[i][1]]-1)*s1,q);
}
int main()
{
    int q,w;
    read(n);
    fo(i,2,n)read(q),link(q,i);
    dfs1(1,0);
    dfs2(1,0,0);
    fo(i,1,n)printf("%.1lf ",ans[i]);
    printf("\n");
    return 0;
}
借助Gemini 3 Pro高效解决课题申报中的五大核心痛点,亲测有效经验分享 之前给大家分享过关于AI辅助课题申报的相关的内容,涵盖了申报书部分撰写技巧,但没针对性拆解各位同仁在实际申报时遇到的卡壳的地方。比如选题范围拿捏不准,定的太大,根本没法落地完成;定的太小,研究价值则体现不了;写综述时,容易单纯罗列文献,缺乏批判性视角,没办法自然融入自己的判断,找不到研究缺口;研究方法部分,可能担心方法设计不够严谨,别人难以复现.....针对这些申报中的高频痛点,接下来七哥会从五个核心要点出发,借助Gemini 3 Pro高效解决这些痛点。 阅读详情

相关推荐

icem二维非结构网格划分_ICEM CFD网格装配

正文共:718字7图 预计阅读时间:2分钟1 前言 对于一些大型的复杂的网格划分,可以将整个模型切分成多个子模型(二维几何用线切分,三维模型用面切分),然后对各个模型单独划分网格,最终装配在一起。这和机械设计的零件设计和装配设计有点相似,这个功...

weixin_39908758的博客 1625

Another Sith Tournament

链接:http://acm.hust.edu.cn/vjudge/problem/401746/origin 题目: The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random

veget_chicken的博客 402

ENVI 5.6保姆级教程:高分七号DLC影像从打开到融合的完整流程(附避坑指南)

本文详细介绍了ENVI 5.6处理高分七号DLC影像的完整流程,包括环境准备、数据解压、正射校正、图像融合等关键步骤。特别针对国产卫星数据处理的独特挑战,提供了实用的避坑指南和优化技巧,帮助用户高效完成光学影像的预处理和质量提升。

weixin_33269743的博客 382

Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压

题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output 问题描述 The rules of Sith Tournament are well known to ever...

weixin_30734435的博客 166

告别regsvr32!易语言调用大漠插件dm.dll的免注册实战(附Win7/10/11避坑指南)

本文详细介绍了易语言如何免注册调用大漠插件dm.dll的实战方法,通过`dmreg.dll`实现真正的免注册调用,规避了传统`regsvr32`注册方式带来的权限和兼容性问题。文章包含核心原理剖析、易语言实现细节、多系统兼容性方案及高级应用场景,帮助开发者实现绿色化部署,提升自动化脚本开发效率。

weixin_42553471的博客 303

基于深度学习的行人车辆检测与计数系统(UI界面+YOLOv8/v7/v6/v5代码+训练数据集)

从YOLOv1到最新的YOLOv8,其网络结构、训练策略和损失函数不断优化,性能持续提升。image_path, _ = QFileDialog.getOpenFileName(self, "选择图片文件", "", "Image Files (*.jpg *.png *.jpeg *.bmp)")video_path, _ = QFileDialog.getOpenFileName(self, "选择视频文件", "", "Video Files (*.mp4 *.avi *.mov *.mkv)")

YOLO 227

Codeforces Round #362 (Div. 2) D 树形dp

链接:戳这里 D. Puzzles time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Barney lives in country USC (United States of Charzeh). USC has

Cross 1265

巨正则蒙特卡洛—甲烷和二氧化碳的竞争吸附GCMC

巨正则蒙特卡洛—甲烷和二氧化碳的竞争吸附GCMC

Rockyoung 8021

Puzzles (树形dp+组合数学)

Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney’s not sure why it is

Twillz的博客 562

14、微电网控制方法与建模分析

本文详细探讨了微电网的控制方法与建模分析,包括逆变器的小信号状态空间模型、网络模型、负载模型及其组合形成的完整微电网模型。通过对系统特征值和灵敏度因子的分析,揭示了不同模式与系统参数之间的关系。文章还提出了多个研究问题,如岛式系统控制器设计、风力发电控制、并网变换器控制等,为微电网的稳定性分析和优化控制提供了理论支持和实践方向。

elastic6hunter的博客 124

知识图谱:综述

第一种理解:知识图谱本质上是语义网络。本体论是语义网络中最重要的一个要素。第二种理解:知识图谱也叫做多关系图,由多种类型的节点和多种类型的边组成。课程以第二种理解为主。

u013250861的博客 479

[CF678E] Another Sith Tournament([JZOJ4648] 锦标赛)

Description The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. A

Never give in. 792

北斗导航 | 从北一到北二再到北三,你应该知道的北斗导航系统

博主github:https://github.com/MichaelBeechan 博主优快云:https://blog.youkuaiyun.com/u011344545 一、引言 我国高度重视北斗系统的建设和发展。自20世纪80年代开始探索适合我们国家国情的卫星导航系统发展道路,形成了“三步走”的发展战略:2000年底,建成北斗一号导航系统,向我国广大用户提供服务;2012年底,建成北斗二号导航系统,...

尘世冰封的专栏 3080

cf678E. Another Sith Tournament

题目大意:有n个选手,给你每个选手战胜另一个选手的概率。赛事为擂台战,选手1很特殊,他可以调换选手的出场顺序,使得自己的胜率最大,求1的胜率。n 题解:如果由初始状态往后递推明显是不行的,因为1可以改变出场顺序状态递推太过困难(选手比赛并不是随机的),我们可以从最终状态开始倒着递推,即确定1必胜,其余状态倒着递推,最后得到都是在1必胜的前提下,dp[I][J](i为擂主,选手状态为j)的概率。

WJSZMRX 654

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an &ldquo;advanced algorithms&rdquo; book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

[CF696B] Puzzles([JZOJ4647] 寻找)

Description Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney’s not s

Never give in. 1539

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

codeforces 697D Puzzles (树形dp 期望 推荐)

codeforces 697D Puzzles (树形dp 期望 推荐)

Tc的专栏 1156

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Codeforces - Another Sith Tournament

题目链接:Codeforces - Another Sith Tournament 这个数据,很明显的状压dp。 我们令 dp[s]为当前状态为s,1获胜的最大概率。二进制01代表死没死。 怎么转移呢?枚举两个不同的人取max。 AC代码: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include&lt;bits/stdc++.h...

青烟绕指柔的博客 566

Codeforces-696B Puzzles

Barney lives in country USC (United States of Charzeh). USC hasncities numbered from1throughnandn - 1roads between them. Cities and roads of USC form a rooted tree (Barney's not sure w...

weixin_30565327的博客 268

JZOJ.4647 寻找

结论题

Luckfort 409

Codeforces 678E(Another Sith Tournament)

题目链接:传送门 题目大意:有n个人决斗(n&lt;=18),每两个人之间都有一定几率杀死对方,一次进行一次决斗,胜利者成为擂主继续接受决斗直到只剩下一个人,你是一号,问你最大有多大几率存活到最后。 题目思路:看到n&lt;=18一般都能想到状态压缩DP,但是当时并没有想到怎么转移状态,下来补题发现了一个好博客讲的很详细 传送门      最后自己理解完后也讲一讲大致的思路首先一个二维DP数...

weixin_30301183的博客 344

Codeforces 678E Another Sith Tournament(状压dp,概率dp)

题意:n个人的擂台赛,起初主角选一个人作为擂主,然后主角选择人上去打擂,直到剩最后一个人,并且主角是擂主,问最后主角是擂主的概率最大是多少 题解:dp[i][j]表示i状态下,j是擂主,最后主角胜出的概率             dp[i][j] = max(dp[i - (1             ans = max(dp[((1             刚开始一直没想通为何要倒着dp

matrix5267的博客 504

CF678E Another Sith Tournament(概率dp+状压dp)

这题又想了会???一开始题都没读对orz。。其实就是让你安排一个比赛顺序,要求1最后存活的概率最大,求这个最大的概率。dp[s][i]表示状态s时擂主为i+1,最后1活下来的最大概率 。我们考虑倒着推(因为正着推难以统计答案x),则状态转移很显然:见代码。。。初始值给dp[1][0]=1,因为要求最后1存活下来。复杂度O(2^n*n^2)

Icefox的博客 582

cf 678E - Another Sith Tournament 【状压dp】

题意:        一共有n个人打擂台,第一个人是主角,他能任意选择那两个人相互比较,赢得成为擂主,继续和其他人比较,       问,主角想赢的概率最大多大。 题解:        dp[i][j]代表存活人集合为i的情况下j为擂主,主角获胜的概率,       so : dp[stat][i]=max(dp[stat][i],a[i][j]*dp[stat^

zoro_n的博客 385

Codeforces 678E Another Sith Tournament(状压dp)

一个n个人的擂台赛,开头主角随便选一个人当擂主,一个人打擂一个n个人的擂台赛,开头主角随便选一个人当擂主,一个人打擂 然后赢得就变成擂主然后赢得就变成擂主 问你最后主角赢下来的概率问你最后主角赢下来的概率 读错题了,搞了半天,不然好像感觉很蠢读错题了,搞了半天,不然好像感觉很蠢 dp[s][i]表示当前活着的人状态是s,i是擂主dp[s][i]表示当前活着的人状态是s,i是擂主 然后选一个

Miracle_ma的专栏 608

Codeforces 696B 树形dp,概率

B. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in country USC (United States of Cha...

162

【Codeforces Round 362 (Div 2)D】【树的遍历 概率均分思想】Puzzles 兄弟节点的等概率遍历下 树的遍历每点期望时间戳

D. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in country USC (United States of Cha

snowy_smile的博客 820
上一篇: 【JZOJ 4639】Angel Beats!
下一篇: 【Codeforces 678E】Another Sith Tournament &【JZOJ 4648】锦标赛
HOWARLI
博客等级 码龄11年 109粉丝 378原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值