传送门

C. Second price auction
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.

However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.

Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability.

Determine the expected value that the winner will have to pay in a second-price auction.

Input

The first line of input contains an integer number n (2 ≤ n ≤ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 ≤ Li ≤ Ri ≤ 10000) describing the i-th company's bid preferences.

This problem doesn't have subproblems. You will get 8 points for the correct submission.

Output

Output the answer with absolute or relative error no more than 1e - 9.

Sample test(s)
Input
3
4 7
8 10
5 5
Output
5.7500000000
Input
3
2 5
3 4
1 6
Output
3.5000000000
Note

Consider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5·5 + 0.25·6 + 0.25·7 = 5.75.

枚举最大的报价比较困难,但是可以枚举第二高的报价,就很easy了

9867472 2015-02-16 11:04:57 njczy2010 513C - Second price auction GNU C++ Accepted 15 ms 0 KB
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 7
#define M 10005
//#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define ull unsigned long long
#define LL long long
#define eps 1e-6
//#define inf 2147483647
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n;
int l[N],r[N];
double ans; void ini()
{
ans=;
int i;
for(i=;i<=n;i++){
scanf("%d%d",&l[i],&r[i]);
}
} void solve()
{
int i,j,k,v;
double p,pu,pd;
for(i=;i<=n;i++){
for(j=;j<=n;j++){
if(j==i) continue;
p=1.0/(r[j]-l[j]+);
for(v=l[j];v<=r[j];v++){
if(i>j){
if(l[i]>=v) pu=1.0;
else if(r[i]<v){ pu=0.0; continue;}
else pu=1.0*(r[i]-v+)/(r[i]-l[i]+);
}
else{
if(l[i]>v) pu=1.0;
else if(r[i]<=v){ pu=0.0; continue;}
else pu=1.0*(r[i]-v+-)/(r[i]-l[i]+);
}
pd=1.0;
for(k=;k<=n;k++){
if(k==i || k==j) continue;
if(j>k){
if(r[k]<=v) pd*=1.0;
else if(l[k]>v) pd*=;
else pd*=1.0*(v-l[k]+)/(r[k]-l[k]+);
}
else{
if(r[k]<v) pd*=1.0;
else if(l[k]>=v) pd*=;
else pd*=1.0*(v-l[k]+-)/(r[k]-l[k]+);
}
}
ans+=1.0*v*p*pu*pd;
}
}
}
} void out()
{
printf("%.10f\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%d",&n)!=EOF)
{
ini();
solve();
out();
}
return ;
}

codeforces Rockethon 2015 C Second price auction [想法]的更多相关文章

  1. Rockethon 2015

    A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: ...

  2. Codeforces Round Rockethon 2015

    A. Game 题目大意:A有N1个球,B有N2个球,A每次可以扔1-K1个球,B每次可以扔1-K2个球,谁先不能操作谁熟 思路:.....显然每次扔一个球最优.... #include<ios ...

  3. CodeForces 219B Special Offer! Super Price 999 Bourles!

    Special Offer! Super Price 999 Bourles! Time Limit:1000MS     Memory Limit:262144KB     64bit IO For ...

  4. Codeforces 602B Approximating a Constant Range(想法题)

    B. Approximating a Constant Range When Xellos was doing a practice course in university, he once had ...

  5. Codeforces 599C Day at the Beach(想法题,排序)

    C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunate ...

  6. 【Codeforces Rockethon 2014】Solutions

    转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...

  7. codeforces 391E2 (【Codeforces Rockethon 2014】E2)

    题目:http://codeforces.com/problemset/problem/391/E2    题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树 ...

  8. codeforces 1282B2. K for the Price of One (Hard Version) (dp)

    链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...

  9. Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)

    A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...

随机推荐

  1. Maximal Discount

    Description: Linda is a shopaholic. Whenever there is a discount of the kind where you can buy three ...

  2. Java格式规范及注释的用法

    /* 需求:演示一个Hello World的Java小程序 思路: 1.定义一个类.因为Java程序都是定义在类中,Java程序都是以类的形式存在的,类的形式其实就是字节码的最终体现 2.定义一个主函 ...

  3. web页面调用IOS的事件

    /** * js 调用ios的方法 * @param callback */ function connectWebViewJavascriptBridge(callback) { if (windo ...

  4. uva12433 Rent a Car

    init 一开始搞成2*n+2了...囧  所以初始化很重要! 然后提交的时候忘了删调试的数据了..囧 技巧:设立虚拟节点 建图比较麻烦(非常). 要考虑到保养完了的车可以免费再用 设立S,T  ,1 ...

  5. uva1610 Party Games

    细节值得注意 注意vector<string>是可以直接sort的! #include <iostream> #include <string> #include ...

  6. 如何在一次请求中通过JS中获取Url中的参数

    从A跳转到B,携带参数 例如: /pc/B.jsp?item=123456 B页面在js可以直接用 var item='${param.item}'; 这样就拿到啦 还有一种方法 定义一个函数   f ...

  7. matlab 随笔

    <<matlab高级编程技巧与应用:45个案例分析>> 一. 重新认识向量化编程 1.向量化编程与循环的比较 2.预分配内存更好 3.matlab中是列优先 4.归一化 数据归 ...

  8. 在window下搭建即时即用的hyperledger fabric 的环境

    有版本号的严格按要求,遇到不少坑 1)安装git  版本无要求 2)安装go  1.9   配置环境变量 3)安装Vagrant  1.9.4 4)安装VirtualBox  5.1.28 5)在go ...

  9. eclipse下svn的分支与合并指南 - 更新版

    http://wenku.baidu.com/link?url=ul5vzBHZpHgzENp46RQwTYrkCUYLeVg9TuhmPM_qisR1BGzp6Qca7onhS-SOzwDYuYdA ...

  10. swift中的as?和as!

    as操作符用来把某个实例转型为另外的类型,由于实例转型可能失败,因此Swift为as操作符提供了两种形式:选项形式as?和强制形式as 选项形式(as?)的操作执行转换并返回期望类型的一个选项值,如果 ...