zoukankan      html  css  js  c++  java
  • E. Playlist 夜

    http://codeforces.com/contest/268/problem/E

    这道题的关键在于要提前排序 假设有两个相邻的顺序为

    (l1,p1)   (l2,p2)

    这样的话时间为 四种可能性的和

    1,(l1+l2)*p1*p2

    2,(2*l1+l2)*p1*(1-p2)

    3,(l1+l2)*(1-p1)*p2

    4,(l1+l2)*(1-p1)*(1-p2)

    相反顺序的话 (l2,p2)    (l1,p1)

    1,(l2+l1)*p1*p2

    2,(2*l2+l1)*p2*(1-p1)

    3,(l2+l1)*(1-p2)*p1

    4,(l2+l1)*(1-p2)*(1-p1)

    第一种顺序是我们选择的所有要大于第二中顺序 经过化简得

    l1*(p1-p1*p2)>l2*(p2-p1*p2)

    这个就是排序的函数

    排序后从头到尾搜一遍 根据概率计算总时间

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<map>
    #include<vector>
    #include<stack>
    #include<set>
    #include<map>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #define LL long long
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    using namespace std;
    const int INF=0x3f3f3f3f;
    //const int MOD=1000000009;
    const int N=50005;
    struct node
    {
        int l;
        double p;
    }mem[N];
    double t[N];
    bool cmp(node x,node y)
    {
        return (x.l*(x.p-x.p*y.p)>y.l*(y.p-x.p*y.p));
    }
    int main()
    {
        //freopen("data.in","r",stdin);
        int n;
        while(cin>>n)
        {
            for(int i=1;i<=n;++i)
            {
                cin>>mem[i].l>>mem[i].p;
                mem[i].p=mem[i].p/100.0;
            }
            sort(mem+1,mem+n+1,cmp);
            t[0]=0.0;
            double ans=0.0;
            for(int i=1;i<=n;++i)
            {
                t[i]=mem[i].l*mem[i].p+t[i-1];
                ans+=(mem[i].l*mem[i].p+(1.0-mem[i].p)*(t[i-1]+mem[i].l));
            }
            printf("%.9lf\n",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    神兽保佑-代码无BUG
    HDU 1022 Train Problem I (数据结构 —— 栈)
    iOS开发
    漫谈程序猿系列:无BUG不生活
    王立平--Unity破解
    java远程调用rmi入门实例
    高仿美团iOS版,版本5.7
    JAVA日志系统
    读《互联网创业password》之随想
    解决iOS空指针数据的问题
  • 原文地址:https://www.cnblogs.com/liulangye/p/2882490.html
Copyright © 2011-2022 走看看