题目链接: 传送门

Playlist

time limit per test:1 second     memory limit per test:256 megabytes

Description

Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to listen to the songs.
Of course, there are some songs that Manao doesn't particuarly enjoy. To get more pleasure from the received songs, he invented the following procedure of listening to the playlist:

  • If after listening to some song Manao realizes that he liked it, then he remembers it and starts to listen to the next unlistened song.
  • If after listening to some song Manao realizes that he did not like it, he listens to all the songs he liked up to this point and then begins to listen to the next unlistened song.

For example, if Manao has four songs in the playlist, A, B, C, D (in the corresponding order) and he is going to like songs A and C in the end, then the order of listening is the following:

  • 1、Manao listens to A, he likes it, he remembers it.
  • 2、Manao listens to B, he does not like it, so he listens to A, again.
  • 3、Manao listens to C, he likes the song and he remembers it, too.
  • 4、Manao listens to D, but does not enjoy it and re-listens to songs A and C.
    That is, in the end Manao listens to song A three times, to song C twice and songs B and D once. Note that if Manao once liked a song, he will never dislike it on a subsequent listening.
    Manao has received n songs: the i-th of them is li seconds long and Manao may like it with a probability of pi percents. The songs could get on Manao's playlist in any order, so Manao wants to know the maximum expected value of the number of seconds after which the listening process will be over, for all possible permutations of the songs in the playlist.

Input

The first line contains a single integer n (1 ≤ n ≤ 50000). The i-th of the following n lines contains two integers, separated by a single space — li and pi (15 ≤ li ≤ 1000, 0 ≤ pi ≤ 100) — the length of the i-th song in seconds and the probability that Manao will like the song, in percents.

Output

In a single line print a single real number — the maximum expected listening time over all permutations of songs. The answer will be considered valid if the absolute or relative error does not exceed 10 - 9.

Sample Input

3
150 20
150 50
100 50

4
300 0
300 50
240 50
360 80

Sample Output

537.500000000

2121.000000000

解题思路

  • 1.Consider any two songs which are at positions i and j (i < j) in the playlist. If Manao liked song i and disliked song j, then song i will be listened to again. Therefore, with probability,code> p[i](1-p[j]),/code> the process length will increase by L[i]. The sum of,code> L[i]p[i](1-p[j]) over all pairs (plus the length of all songs since Manao listens to them at least once) is the expected length for the fixed sequence.
    So we have that if there are two songs (l1, p1) and (l2, p2), the first one should be placed earlier in the playlist if l1
    p1(1-p2)>l2p2*(1-p1) and later otherwise.
  • 2.Suppose we have fixed j and are counting the contribution of song j towards the answer if Manao dislikes it. This value is(l1p1 + l2p2 + ... + l[j-1]p[j-1]). For j+1, the corresponding value will be(l1p1+...+l[j-1]p[j-1]+l[j]p[j]). It turns out that these values differ in only a single summand, so we can compute each of them in O(1)
    一开始按照直观感觉来排序,果然交上去就wa,还是刷题太少,这些题目都是套路啊
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct Node{
    double val,rate;
};

bool cmp(Node x,Node y)
{
    return x.val*x.rate*(1-y.rate) > y.val*y.rate*(1-x.rate);
}

int main()
{
    int N;
    double sum = 0,tmp = 0;
    Node node[50005];
    memset(node,0,sizeof(node));
    scanf("%d",&N);
    for (int i = 0;i < N;i++)
    {
        scanf("%lf%lf",&node[i].val,&node[i].rate);
        node[i].rate /= 100;
    }
    sort(node,node+N,cmp);
    for (int i = 0;i < N;i++)
    {
        sum += node[i].val;
        sum += tmp*(1-node[i].rate);
        tmp += node[i].val*node[i].rate;
    }
    printf("%.9lf\n",sum);
}

CF 268E Playlist(贪心)的更多相关文章

  1. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  2. CF 949D Curfew——贪心(思路!!!)

    题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...

  3. CF Covered Path (贪心)

    Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. CF 389 E 贪心(第一次遇到这么水的E)

    http://codeforces.com/contest/389/problem/E 这道题目刚开始想的特别麻烦...但是没想到竟然是贪心 我们只需要知道偶数的时候可以对称取的,然后奇数的时候没次取 ...

  5. CF 463A && 463B 贪心 && 463C 霍夫曼树 && 463D 树形dp && 463E 线段树

    http://codeforces.com/contest/462 A:Appleman and Easy Task 要求是否全部的字符都挨着偶数个'o' #include <cstdio> ...

  6. cf 之lis+贪心+思维+并查集

    https://codeforces.com/contest/1257/problem/E 题意:有三个集合集合里面的数字可以随意变换位置,不同集合的数字,如从第一个A集合取一个数字到B集合那操作数+ ...

  7. 【清真dp】cf1144G. Two Merged Sequences

    成就:赛后在cf使用错误的贪心通过一题 成就:在cf上赛后提交hack数据 成就:在cf上赛后hack自己 题目大意 有一长度$n \le 2\times 10^5$的序列,要求判断是否能够划分为一个 ...

  8. Codeforces Round #401 (Div. 2) 离翻身就差2分钟

    Codeforces Round #401 (Div. 2) 很happy,现场榜很happy,完全将昨晚的不悦忘了.终判我校一片惨白,小董同学怒怼D\E,离AK就差一个C了,于是我AC了C题还剩35 ...

  9. Codeforces Edu Round 62 A-E

    A. Detective Book 模拟题,有一些细节需要注意. #include <cstdio> #include <iostream> #include <cmat ...

随机推荐

  1. Nodejs进阶:基于express+multer的文件上传

    关于作者 程序猿小卡,前腾讯IMWEB团队成员,阿里云栖社区专家博主.欢迎加入 Express前端交流群(197339705). 正在填坑:<Nodejs学习笔记> / <Expre ...

  2. 自己画WinForm 皮肤包括默认控件

    好久没来博客园,今天捣鼓到现在就是为了把之前的皮肤控件完善好, 之前也看了很多技术文章,大多数都是自己重写系统控件实现换肤,几乎没有像东日的(IrisSkin)控件一样 添加一个组件 把系统的皮肤全换 ...

  3. Entity Framework 出现 "此 ObjectContext 实例已释放,不可再用于需要连接的操作" 的错误

    原因 Entity的导航属性在View中使用,但是该Entity所在的Context已经在Controller中通过 using 释放掉:但是Entity又具有Deferred Query Evalu ...

  4. SD卡状态广播

    SD状态发生改变的时候会对外发送广播.SD卡的状态一般有挂载.未挂载和无SD卡. 清单文件 一个广播接受者可以接受多条广播.这里在意图过滤器中添加是data属性是因为广播也需要进行匹配的.对方发送的广 ...

  5. 前端 head 中mate 详解

    <meta name="viewport" content="width=device-width,height=device-height,initial-sca ...

  6. 一次神奇的WCF的404错误解决

    现象:浏览器中可以访问元数据,但是运行的时候却报404的异常,说目标地址找不到. 折腾了一下午. 引用服务后config中的client的address是这样的http://host/aspx/Ser ...

  7. HashTable、HashMap、HashSet

    1. HashMap 1)  hashmap的数据结构 Hashmap是一个数组和链表的结合体(在数据结构称“链表散列“),如下图示: 当我们往hashmap中put元素的时候,先根据key的hash ...

  8. tomcat报错

    错误日志如下: 十月 10, 2016 10:44:57 上午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.serv ...

  9. 基于tomcat-jQ-springMVC-bootstrap的公司产品管理WEB应用

    管理员登录后台以后才能操作 ,权限管理只有一个管理员, 系统的主要作用是查看所有的 “公司列表”, 并查看该公司的”产品“, 用户可以对该公司的产品进行添加或者删除, 添加或者删除公司等 , 添加产品 ...

  10. mnsday1t1

    贪心地选取两个后缀,然后往前补全,贪心地补全前k个不同的字符 我写了个沙茶dp,结果T掉了,明明都是n3的... #include<iostream> #include<stdio. ...