当前位置:网站首页>CCF CSP 202109-4 collect cards
CCF CSP 202109-4 collect cards
2022-06-10 22:36:00 【Brienzz】
Define the storage structure
Structure : Card draw status , The layer number ( Extraction times ), Probability product
Define a queue , Simulate the hierarchical traversal process of the tree
Input
Total number of cards read n And coins k Number of cards changed
Read in the card to get the probability
Use queues to simulate n Hierarchy traversal of fork tree
Every outgoing node
- Judge whether the card drawing is completed
- If it's done , Calculate the probability product , And sum it up
- If not done , Keep drawing , Generate child nodes , Calculate the probability product , And put the child nodes in the queue
The queue is empty ( End of traversal ), Output results
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
double p[16];// Number of cards n Less than or equal to 16, The corresponding probability number is less than or equal to 16
int n,k;
struct node{
int state;// Card draw status [ It's essentially a vector , Someone is 1, Indicates the card drawn to this position ]
int level;// The layer number ( Extraction times )
double p;// Probability product
};
int main(){
scanf("%d%d",&n,&k);// Total number of cards read n And coins k Number of cards changed
for(int i=0;i<n;i++) scanf("%lf",p+i);// For the first i The probability of a card is p[i-1]
double ans = 0;// Record the expected number of cards drawn
node nodecur,nodechild;
queue<node> q;// Define a queue , Simulate the hierarchical traversal process of the tree
// Initial root node
nodecur.state = 0;
nodecur.level = 0;
nodecur.p = 1;
// Start n Hierarchy traversal of fork tree
q.push(nodecur);
while(!q.empty()){
nodecur = q.front();
q.pop();
int cnt = 0;// Record the number of different types of cards drawn
for(int i=0;i<n;i++)
if((nodecur.state>>i)&1) cnt++;
//nodecur.level-cnt Is the number of coins
if(cnt+(nodecur.level-cnt)/k>=n){
ans = ans += nodecur.p * nodecur.level; // Cumulative probability product * The layer number
continue;// here , There is no need to generate child nodes , Just skip , The reason is that the conditions have been met , There is no need to draw
}
for(int i=0;i<n;i++){// Generate child nodes
nodechild.p = nodecur.p*p[i];// Calculate the probability product of child nodes
nodechild.state = nodecur.state|(1<<(n-i-1));
nodechild.level = nodecur.level + 1;
q.push(nodechild);// Queue child nodes
}
}
printf("%.10lf\n",ans);// Title Example 2 It is reserved to the... After the decimal point 10 position
return 0;
}边栏推荐
- Latex error: file ‘xxx.sty‘ not found
- 1.Tornado简介&&本专栏搭建tornado项目简介
- [tcapulusdb knowledge base] Introduction to tcapulusdb process startup
- 存储引擎分析
- 记录(三)
- What are MySQL clustered indexes and nonclustered indexes?
- Different ways to create four indexes in MySQL
- Error parsing mapper XML
- [tcapulusdb knowledge base] Introduction to the machine where the tcapulusdb viewing process is located
- [tcapulusdb knowledge base] Introduction to tcapulusdb patrol inspection statistics
猜你喜欢

How to do well in the top-level design of informatization in the process of informatization upgrading of traditional enterprises

【TcaplusDB知识库】TcaplusDB巡检统计介绍

Model construction of mmdetection

存储引擎分析

Matlab - Implementation of evolutionary game theory

Diablo immortality database station address Diablo immortality database website
![[tcapulusdb knowledge base] Introduction to tcapulusdb process startup](/img/df/08a5e9b939ab158a86c75c92697864.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb process startup

leetcode 130. Surrounded regions (medium)

Whale conference empowers intelligent epidemic prevention

【Xpath】使用following-sibling获取后面的同级节点
随机推荐
README
小微企业如何低成本搭建微官网
罗永浩:我要是负责人 能让苹果产品上去三个台阶不止
Pytorch 安装超简单
Diablo immortality database station address Diablo immortality database website
ArrayList的扩容机制
mathtype7.x的基本使用
Capacity expansion mechanism of ArrayList
在D天内送达包裹的能力[抽象类二分--抽象判定方式]
README
GMPNN:Drug-drug interaction prediction with learnable size-adaptive molecular substructures.
Use of C language qsort() function (detailed explanation)
[tcapulusdb knowledge base] Introduction to tcapulusdb push configuration
Pytorch installation is super simple
笔记(四)- 多线程
JVM运行时数据区
Latex error: file ‘xxx.sty‘ not found
datagrip 报错 “The specified database user/password combination is rejected...”的解决方法
TypeScript - 声明文件和内置对象
鲸会务会议分享:大会难办怎么办?