• codeforces Rockethon 2015 C Second price auction [想法]


    传送门

    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
      1 #include<iostream>
      2 #include<cstring>
      3 #include<cstdlib>
      4 #include<cstdio>
      5 #include<algorithm>
      6 #include<cmath>
      7 #include<queue>
      8 #include<map>
      9 #include<set>
     10 #include<stack>
     11 #include<string>
     12 
     13 #define N 7
     14 #define M 10005
     15 //#define mod 10000007
     16 //#define p 10000007
     17 #define mod2 1000000000
     18 #define ll long long
     19 #define ull unsigned long long
     20 #define LL long long
     21 #define eps 1e-6
     22 //#define inf 2147483647
     23 #define maxi(a,b) (a)>(b)? (a) : (b)
     24 #define mini(a,b) (a)<(b)? (a) : (b)
     25 
     26 using namespace std;
     27 
     28 int n;
     29 int l[N],r[N];
     30 double ans;
     31 
     32 void ini()
     33 {
     34     ans=0;
     35     int i;
     36     for(i=1;i<=n;i++){
     37         scanf("%d%d",&l[i],&r[i]);
     38     }
     39 }
     40 
     41 void solve()
     42 {
     43     int i,j,k,v;
     44     double p,pu,pd;
     45     for(i=1;i<=n;i++){
     46         for(j=1;j<=n;j++){
     47             if(j==i) continue;
     48             p=1.0/(r[j]-l[j]+1);
     49             for(v=l[j];v<=r[j];v++){
     50                 if(i>j){
     51                     if(l[i]>=v) pu=1.0;
     52                     else if(r[i]<v){ pu=0.0; continue;}
     53                     else pu=1.0*(r[i]-v+1)/(r[i]-l[i]+1);
     54                 }
     55                 else{
     56                     if(l[i]>v) pu=1.0;
     57                     else if(r[i]<=v){ pu=0.0; continue;}
     58                     else pu=1.0*(r[i]-v+1-1)/(r[i]-l[i]+1);
     59                 }
     60                 pd=1.0;
     61                 for(k=1;k<=n;k++){
     62                     if(k==i || k==j) continue;
     63                     if(j>k){
     64                         if(r[k]<=v) pd*=1.0;
     65                         else if(l[k]>v) pd*=0;
     66                         else pd*=1.0*(v-l[k]+1)/(r[k]-l[k]+1);
     67                     }
     68                     else{
     69                         if(r[k]<v) pd*=1.0;
     70                         else if(l[k]>=v) pd*=0;
     71                         else pd*=1.0*(v-l[k]+1-1)/(r[k]-l[k]+1);
     72                     }
     73                 }
     74                 ans+=1.0*v*p*pu*pd;
     75             }
     76         }
     77     }
     78 }
     79 
     80 void out()
     81 {
     82     printf("%.10f
    ",ans);
     83 }
     84 
     85 int main()
     86 {
     87     //freopen("data.in","r",stdin);
     88     //freopen("data.out","w",stdout);
     89     //scanf("%d",&T);
     90     //for(int ccnt=1;ccnt<=T;ccnt++)
     91     //while(T--)
     92     //scanf("%d%d",&n,&m);
     93     while(scanf("%d",&n)!=EOF)
     94     {
     95         ini();
     96         solve();
     97         out();
     98     }
     99     return 0;
    100 }
  • 相关阅读:
    SharePoint开发中可能用到的各种Context(上下文)
    SharePoint 2013中的视频体验增强(1)——把大象装进冰箱
    SharePoint 2013之Office Web Apps Server(1)
    Office 2013 (Wave 15)来了
    SharePoint 2013新特性:图像呈现形式(Image Rendition)
    SharePoint 2013之Office Web Apps Server(2)
    在自己的代码中获取SharePoint的存储占用情况
    Showing Hyperlink Cues with CSS
    (翻译) 价目表:实例和最佳策略
    用CSS制作大背景网站,以及80个大背景图片网站。
  • 原文地址:https://www.cnblogs.com/njczy2010/p/4294237.html
Copyright © 2020-2023  润新知