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: 思路:由于无时间复杂 ...
随机推荐
- iOS 音频视频制作
--iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...
- BaseAtapter
本文用于实现一个通用的BaseAdapter类,统一产品的Adapter类,作为一个工具类,减少重复性工作,增加开发效率. 序 我们在开发项目的过程中,经常会用到ListView.GridView这一 ...
- SQL函数 Nullif
函数 Nullif 功能: 如果两个函数都为空字符串则返回null 语法: Nullif(参数1,参数2) 一般该函数与函数coalesc一起使用 例: coalesce ( nullif ( [参数 ...
- upupw nginx服务器 rewrite设置
最近开始尝试使用upupw的Nginx套件做开发,感觉还挺不错的,也遇到了一些问题,决定在这里记录一下,同时也希望可以帮助到一些人. 用习惯了Apache,改用Nginx之后会有些不适应,但是咬咬牙就 ...
- 职业生涯手记——电视剧剧情O.O
很多电视剧.偶像剧.电影里出现过一些场景,从来没想过狗血剧情是来源于现实.. 直到上周一开始,我慢慢相信了.. 事情是这样的. 我们小组有个组员H,从上周一开始他每天都去公司的座机电话接1~2个电话, ...
- 深度剖析 MySQL 事务隔离
概述 今天主要分享下MySQL事务隔离级别的实现原理,因为只有InnoDB支持事务,所以这里的事务隔离级别是指InnoDB下的事务隔离级别. 隔离级别 读未提交:一个事务可以读取到另一个事务未提交的修 ...
- easyui权限管理
在easyui上实现权限的管理 所谓权限:指的是系统中的资源,资源包括菜单资源(学习情况报表,账号审核...)以及按钮资源所谓角色:指的是系统中的权限集合(每一个角色对应着哪些权限集合) 1.一星权限 ...
- 串的基本操作(KMP算法实现)
#include <iostream> #include <math.h> using namespace std; void StrAssign(char *T) { cha ...
- MySQL丨03丨基本语句
MySQL语句都是以 ; 号结尾的 看库(刘大婶直接面对的是各种档案袋) show databases; 建库(新弄了一个档案袋) create database database_name; 删库( ...
- NTP服务和DNS服务
1.NTP时间服务器 作用:NTP主要用于对计算机的时间同步管理操作 1.1 NTP部署 服务端:192.168.16.6 客户端:192.168.16.7 [root@localhost ~]# ...