codeforces Rockethon 2015 C Second price auction [想法]
2 seconds
256 megabytes
standard input
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.
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 the answer with absolute or relative error no more than 1e - 9.
3
4 7
8 10
5 5
5.7500000000
3
2 5
3 4
1 6
3.5000000000
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 [想法]的更多相关文章
- Rockethon 2015
A Game题意:A,B各自拥有两堆石子,数目分别为n1, n2,每次至少取1个,最多分别取k1,k2个, A先取,最后谁会赢. 分析:显然每次取一个是最优的,n1 > n2时,先手赢. 代码: ...
- Codeforces Round Rockethon 2015
A. Game 题目大意:A有N1个球,B有N2个球,A每次可以扔1-K1个球,B每次可以扔1-K2个球,谁先不能操作谁熟 思路:.....显然每次扔一个球最优.... #include<ios ...
- CodeForces 219B Special Offer! Super Price 999 Bourles!
Special Offer! Super Price 999 Bourles! Time Limit:1000MS Memory Limit:262144KB 64bit IO For ...
- Codeforces 602B Approximating a Constant Range(想法题)
B. Approximating a Constant Range When Xellos was doing a practice course in university, he once had ...
- Codeforces 599C Day at the Beach(想法题,排序)
C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunate ...
- 【Codeforces Rockethon 2014】Solutions
转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...
- codeforces 391E2 (【Codeforces Rockethon 2014】E2)
题目:http://codeforces.com/problemset/problem/391/E2 题意:有三棵树.每棵树有ni个结点,加入两条边把这三棵树连接起来,合并成一棵树.使得合并的树 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
A(By talker): 题意分析:以a(int) op b(int)形式给出两个整数和操作符, 求两个整数是否存在操作符所给定的关系 ,有则输出true,无则输出false: 思路:由于无时间复杂 ...
随机推荐
- logging模块进阶2
1.两种级别设置: 全局级别:生成logger对象后设置的级别 局部级别:生成handler对象设置的级别 我们都知道输出的级别不能低于设定的级别,那么全局级别和局部级别哪一个对输出产生影响? 经过多 ...
- 【学习笔记】OSG 基本几何图元
例:geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 来指定要利用这些数据生成一个怎么样的形状. ...
- SQL的top 100 percent用法
sql="select top 30 * from data where title='"&title1&"' order by id desc" ...
- How To Build Kubernetes Platform (构建Kubernetes平台方案参考)
Architecture Architecture Diagram Non-Prod Environment Prod Environment Cluster Networking Container ...
- jmeter 接口测试简介
前言: 本文主要针对http接口进行测试,使用Jmeter工具实现. Jmter工具设计之初是用于做性能测试的,它在实现对各种接口的调用方面已经做的比较成熟,因此,本次直接使用Jmeter工具来完成对 ...
- DROP TABLE - 删除一个表
SYNOPSIS DROP TABLE name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP TABLE 从数据库中删除表或视图. 只有其所有 ...
- java使用数据库连接池
连接池的实现方式是首先使用JNDI(JavaTM Naming and Directory Interface) 将数据源对象注册为一个命名服务,然后使用JNDI提供的服务接口,按照名称检索对应的数据 ...
- 性能优化 java 24 次阅读 · 读完需要 15 分钟 0
摘要: 技术传播的价值,不仅仅体现在通过商业化产品和开源项目来缩短我们构建应用的路径,加速业务的上线速率,也会体现在优秀程序员在工作效率提升.产品性能优化和用户体验改善等小技巧方面的分享,以提高我们的 ...
- Canvas标签
1.Canvas标签: HTML5<canvas>元素用于图形的绘制,通过脚本(通常是javascript)来完成<canvas>标签只是图形容器,必须使用脚本来绘制图形.你可 ...
- 第一章:systemverilog简介
1.为何要学systemverilog ..... 2.systemverilog起源 ..... 3.systemverilog标准历程 systemverilog3.0 for 综合 system ...