Codeforces 623D [Amazing概率题]

很有趣的一道题吖!

做法:贪心+迭代

  • Sigma(i*(pr[i]-pr[i-1])))=n-sigma(pr[i]), 所以我们贪心地是pr[i]尽可能大。
  • 也就是让pr[i]/pr[i-1]尽可能大。

这种类型的贪心,和17EC-Final的那个最小化方差的题挺相似的。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
using namespace std;
typedef long long LL;

#define rd(x) scanf("%d",&x)
#define prt(x) printf("%d\n", x);
#define prtvec(v) for(int i=0;i<v.size();i++) printf("%d%c", v[i], i==(v.size()-1)?‘\n‘:‘ ‘);
#define sz(x) (int)x.size()
#define pb(x) push_back(x)
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,y,x) for(int i=y;i>=x;i--)

const int N=300000+10;
const double EPS = 1e-8;

int n;
double f[N][102],g[N],p[N];

int main(){
    rd(n); rep(i,1,n) scanf("%lf",&p[i]), p[i]/=100.0;

    rep(i,1,n) f[n][i] = p[i];

    rep(i,n+1,N-1) {
        double mx = 0; int bst = -1;
        rep(j,1,n) {
            double tmp = (1-f[i-1][j])*p[j]/f[i-1][j];
            if (tmp > mx) {
                mx=tmp, bst = j;
            }
        }
        rep(j,1,n) f[i][j]=f[i-1][j];
        f[i][bst]=(1-f[i-1][bst])*p[bst] + f[i-1][bst];
    }

    double res = 0;
    rep(i,n,N-1) {
        g[i]=1;
        rep(j,1,n) g[i]*=f[i][j];
        res=res+i*(g[i]-g[i-1]);
    }
    printf("%.5f\n", res);

}

  

原文地址:https://www.cnblogs.com/RUSH-D-CAT/p/8955538.html

时间: 2024-08-29 20:48:13

Codeforces 623D [Amazing概率题]的相关文章

Codeforces 453A Little Pony and Expected Maximum 概率题Orz

题目链接:点击打开链接 #include <stdio.h> #include <iostream> #include <algorithm> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; int main() { int i, j; double m,n; while(cin>>m>>

HDU 4839 The Game of Coins 概率题。(母函数

The Game of Coins mark: #include"cstdio" #include"iostream" #include"queue" #include"algorithm" #include"set" #include"queue" #include"cmath" #include"string.h" #include"

CodeForces 26C Parquet 构造题

题目链接:点击打开链接 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> #include <set> using namespace std; #define N 105 int n,m,a,b,c; char s[N][N]; set<char>myset; bool inm

概率题

题目1 (2014腾讯笔试题) 36辆车,6个跑道,最少轮数决出前3名. 分析 分6组,每组跑一次,进行排序. 然后每组第一快的人再跑一遍,确定最快的3组. 最后最快的第一组取3个人,第二快的人取2个人(因为最快的人一定在最快的第一组),第三快的人取1个人.共6个人.再跑一遍. 所以总共是6+1+1=8轮. 以下转自:http://www.acmerblog.com/interviews-about-probability-5359.html 题目2 假设你参加了一个游戏节目,现在要从三个密封的

HDU 4576 Robot(概率题)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

写一个随机洗牌函数——概率题

题目描述: 写一个随机洗牌函数.要求洗出的52!种组合都是等概率的. 也就是你洗出的一种组合的概率是1/(52!).假设已经给你一个完美的随机数发生器. 解题思路: 这是一道概率题 随机洗牌,目的是要做到随机性,要求每一张牌出现的概率要相等. 我们常用的普通扑克牌54张,要做到每张牌出现的概率是1/(54!), 抽第一张牌概率:1/54: 抽第二张牌概率:1/53: 抽第三张牌概率:1/52: -- 一直这样随机地拿下去直到拿完最后1张,我们就从52!种可能中取出了一种排列, 这个排列对应的概率

概率题(一)

转载http://noalgo.info/414.html 概率论是计算机科学非常重要的基础学科之一,概率题也是在程序员求职过程中经常遇到的问题.以下总结若干经典的概率题,作为练习. 1. 在半径为1的圆中随机选取一点. 方法1:在x轴[-1,1],y轴[-1,1]的正方形随机选取一点,如果此点在圆内,则即为所求的点.如果不在圆内,则重新随机直到选到了为止. 方法2:从[0, 2*pi)随机选取一个角度,再在这个方向的半径上随机选取一个点.但半径上的点不能均匀选取,选取的概率要和离圆心的距离成正

CodeForces 20B Equation 水题

题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10000000 #define l

codeforces 148D 【概率dp】

题目链接: codeforces 148D Bag of mice 题意:一个包里面有w只白老鼠和b只黑老鼠,公主与龙依次从包中拿老鼠,每次取一只,当龙拿时还会从包中溜走一只,先拿到老鼠的获胜,当背包中没老鼠时且之前没人拿到白老鼠则龙获胜,问公主获胜的概率是多少. 题解: 设dp[i][j]为背包中有i只白老鼠j只黑老鼠时公主获胜的概率 则公主获胜的情况分成三种: 1.直接拿到白老鼠 p1=i/(i+j) 2.公主拿到黑老鼠,龙拿到黑老鼠,逃跑一只黑老鼠 p2=(j/(i+j)) ((j-1)/