Codeforces Rockethon 2015 C

Problem

N个公司在拍卖标价一件商品,每个公司会在各自的[Li,Ri]区间内等概率选取整数出价。出最高价的公司会赢得商品,若有多个公司出最高价,随机一个公司赢得商品。但是,有一条特殊规矩,赢得商品的公司所需付的钱不是它所标价的钱,而是除去它以外的其它公司所标价的钱的最大值。现求,赢得的公司所需付钱的期望。

Limits

TimeLimit(ms):2000

MemoryLimit(MB):256

N∈[2,5]

Li,Ri∈[1,10000]

Look up Original Problem From here

Solution

从[1,104]枚举第二高价,EXP=∑104i=1Pi×i,用此公式求得期望。

Pi=EachiTotal,Eachi表示每一个第二高价的情况数

Total=∏Ni=1(Ri?Li+1),Total表示总情况数

期望还可表示为:EXP=∑104i=1EachiTotal=Each1+Each2+…+Each104Total

不难发现,若当前第二高价为i,则必然有一个公司的标价为i,必然还有一个公司的标价>=i,而其余公司标价<=i。

用上述思想去求Eachi,难点在于要精确地保证不重复计算 。我的方法是两步:1. 枚举每一个标价>i的公司,再状压枚举其余公司的标价为i或者<i,需保证标价为i的公司至少有一个;2. 枚举所有公司标价为i或者<i,需保证标价为i的公司至少有两个。

此外,用概率dp也可以做。

Complexity

TimeComplexity:O(104×N2×2N)

MemoryComplexity:O(N)

My Code

//Hello. I‘m Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define pb(a) push_back(a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define pi 3.1415926535898
#define eps 1e-6
#define MOD 1000000007
#define MAXN
#define N
#define M
int n,mini,maxi;
struct Person{
    int l,r;
}per[10];
double totalsum,sumt;
int main(){
    cin>>n;
    totalsum=1.0;
    mini=INT,maxi=-INT;
    rep(i,0,n){
        scanf("%d %d",&per[i].l,&per[i].r);
        double t=per[i].r-per[i].l+1;
        totalsum*=t;
        mini=min(mini,per[i].l),mini=min(mini,per[i].r);
        maxi=max(maxi,per[i].l),maxi=max(maxi,per[i].r);
    }
    sumt=0;
    repin(now,mini,maxi){
        double sum1=0.0;
        rep(i1,0,n){
            if(per[i1].r<=now) continue;
            rep(i,1,1<<n){
                if(i&(1<<i1)) continue;
                double sum2=per[i1].r-max(now+1,per[i1].l)+1;
                bool ok=true;
                rep(j,0,n){
                    if(j==i1) continue;
                    if((i&(1<<j))==0){
                        if(now<=per[j].l){
                            ok=false;
                            break;
                        }
                        else{
                            double t=min(per[j].r,now-1)-per[j].l+1;
                            sum2*=t;
                        }
                    }
                    else{
                        if(per[j].r<now || now<per[j].l){
                            ok=false;
                            break;
                        }
                    }
                }
                if(!ok) continue;
                sum1+=sum2;
            }
        }
        rep(i,1,1<<n){
            int num=0;
            bool ok=true;
            double sum2=1.0;
            rep(j,0,n){
                if((i&(1<<j))==0){
                    if(now<=per[j].l){
                        ok=false;
                        break;
                    }
                    else{
                        double t=min(per[j].r,now-1)-per[j].l+1;
                        sum2*=t;
                    }
                }
                else{
                    num+=1;
                    if(per[j].r<now || now<per[j].l){
                        ok=false;
                        break;
                    }
                }
            }
            if(num<2 || !ok) continue;
            sum1+=sum2;
        }
        sumt+=now*sum1;
    }
    double ans=sumt/totalsum;
    printf("%.10f\n",ans);
}
时间: 2024-08-02 11:11:18

Codeforces Rockethon 2015 C的相关文章

CODEFORCES Rockethon 2015 B. Permutations

You are given a permutation p of numbers 1,?2,?-,?n. Let's define f(p) as the following sum: Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p). Input The single line of input

codeforces Rockethon 2015

比赛链接:http://codeforces.com/contest/513 A. Game time limit per test 2 seconds memory limit per test 256 megabytes Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second pl

Codeforces Round Rockethon 2015

A. Game 题目大意:A有N1个球,B有N2个球,A每次可以扔1-K1个球,B每次可以扔1-K2个球,谁先不能操作谁熟 思路:.....显然每次扔一个球最优.... 1 #include<iostream> 2 #include<cstdio> 3 #include <math.h> 4 #include<algorithm> 5 #include<string.h> 6 #include<queue> 7 #define MOD

Rockethon 2015

A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: 1 #include <bits/stdc++.h> 2 #define pb push_back 3 #define mp make_pair 4 #define esp 1e-14 5 #define lson l, m, rt<<1 6 #define rson m+1, r,

codeforces 391E2 (【Codeforces Rockethon 2014】E2)

/* 题意:有三棵树,每颗树有ni个结点,添加两条边把这三棵树连接起来,合并成一棵树,使得树中任意两点之间的最短路径 的和最大. 分析: 三棵树要合并成一棵树,则第一棵树必须选择一个点,假设为X,第二棵树必须选择两个点,假设为Y1, Y2,第三棵树必须选择一个点,假设为Z 记第一棵树中所有结点到X的路径总和为:tot1 第二棵树中所有结点到Y1,Y2的路径总和分别为:tot2, tot3 第三棵树中所有结点到Z的路径总和为:tot4; 共有四种情况: 1,每棵树内部的结点之间的距离为常数,可以求

A. Game

这是 Rockethon 2015 的一道题,也是我做codeforces的第一道题,在这里留个纪念.原题在这. 题意为:小明有n1个球,小红有n2个球,每轮游戏,小明可以扔掉a个球(1 <= a <= k1), 小红可以扔掉 (1 <= b <= k2)个球,小明先开始游戏,在小明和小红不是sb的情况下,要是轮到谁了,谁的球扔完了,那么这个人就输了. 输入 n1, n2, k1, k2 , 输出 First (如果第一个人赢)或者 Second (要是第二个人赢) 我就想,要是小

阿尔红军我让我特我问题沃特尔行业

http://www.houzz.com/ideabooks/38419124/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419135/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419147/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419107/thumbs/2015.01.04 http://www.houzz.c

哪敢跟学长这么

不少人面庞上有不由得惊呼出声http://weibo.com/09.16/2015/p/1001603887569338240338http://weibo.com/09.16/2015/p/1001603887569338268443http://weibo.com/09.16/2015/p/1001603887569342462767http://weibo.com/09.16/2015/p/1001603887569342462769http://weibo.com/09.16/2015/

右手缓缓握拢而

火红烈日炸裂的一路冲杀进去吧http://weibo.com/2015/09/16/p/1001603887216807041204http://weibo.com/2015/09/16/p/1001603887216811186273http://weibo.com/2015/09/16/p/1001603887216811186277http://weibo.com/2015/09/16/p/1001603887216811235528http://weibo.com/2015/09/16/