mcpc2017 The Uncertainty of Politics

5096: The Uncertainty of Politics

时间限制: 1 Sec   内存限制: 128 MB   Special Judge

题目描述

You have an upcoming trip to Washington D.C. and you are fascinated with the intricacies of Congressional committee hearings. You wish to attend as many hearings as possible during your trip, and your local representative has provided you with a pass that will get you into the audience of any hearing. But there are some challenges in planning your schedule.
Specifically:
1. There are many committees, and thus many hearings, some of which take place at overlapping times.
2. While the committees are extremely punctual in terms of when to start a hearing, they are notoriously unpredictable in terms of how long the hearing lasts. Fortunately, rules do not actually allow for a filibuster of a committee hearing, so they cannot last forever.
3. It is considered rude to enter a hearing that is already underway, or to leave a hearing before it is complete. Given that you do not wish to embarrass the representative who provided your tickets, if you attend you must attend the entire hearing. Fortunately, hearings are very near to each other; as soon as one hearing is done, you can immediately join another hearing that is about to start.
Well in advance of your trip, Congress publishes a schedule of hearings, indicating for each one the time s at which the hearing will start, and then values a and b which represent, respectively, the shortest and longest possible length of that particular hearing. You are to assume that the actual length of the hearing will be a uniformly random integer over the inclusive interval [a, b]. 
Your goal is to develop a strategy that maximizes the expected number of hearings that you can attend during your trip. As an example, consider a situation in which there are four hearings with parameters as follows:
For this schedule, the optimal strategy will allow you to achieve an expected value of 2.125 hearings. To achieve this, you begin by attending the NASA hearing, which starts at time 3 and ends with equal probability at either time 5 or time 6 (given the hearing length that is uniformly distributed over {2, 3}). If the NASA hearing does end at time 5 you will immediately head to the oil and gas exploration hearing, and there is a  1/4 chance that hearing will end at time 6, allowing you to make yet a third hearing (about hurricane recovery efforts). If the NASA hearing instead ends at time 6, you will go straight to the hurricane hearing. 
By this strategy you will attend 3 hearings 12.5% of the time and 2 hearings the other 87.5% of the time, and thus expected value of 2.125. Note that if you were to start by attending the social media and elections hearing, you might optimistically make four hearings. However, a careful analysis will demonstrate that if you attend the first hearing, your optimal expected value is only 2.10714.

输入

The input begins with an integer n that designates the total number of scheduled hearings (1 ≤ n ≤ 104).
Following that are n lines, each containing three integers s, a, and b, respectively representing the start time, minimum length, and maximum length of a hearing, such that 1 ≤ s ≤ 106 and 1 ≤ a ≤ b ≤ 106. The hearings will be listed in nondecreasing order of their start times.

输出

Display the expected number of hearings of an optimal strategy. Your answer should have an absolute or relative error of at most 10−3.

样例输入

4
1 1 7
3 2 3
5 1 4
6 10 10

样例输出

2.125

题目大意:有n个听证会,给定每个会议开始的时间,最早的结束时间和最晚的时间,求最明智的方案的参加听证会数目的期望值。


蒟蒻的思路:因为参加每一个听证会后最优方案的期望值只会收到它之后的听证会的最优方案的期望值的影响,所以第一反应就是从后往前进行一个DP。对每个听证会,将它的进行时间分为长度为1的m段,每段取在该时刻最大的期望,将一个听证会的所有时刻的最优值加在一起即为该听证会的最优解(如一个听证会进行时间是3-5时刻,那么我们分别取3、4、5这三个时刻能取得最大值,再将这三个值加在一起,最后加上该听证会自身的1,即为该听证会的最优解)


#include <bits/stdc++.h>
struct hearings
{
    int s,a,b;
};
double dp[100005];                    //dp[i]为参加第i个听证会(不参加第i个之前的听证会)的最优方案的期望值
hearings z[100005];
int main()
{
    int i,n;
    scanf("%d",&n);
    for (i=0;i<n;i++)
        scanf("%d%d%d",&z[i].s,&z[i].a,&z[i].b);
    for (i=n-1; i>=0; i--)           //从最后一个听证会往前扫
    {
        int p1,p2,e,k=n-1;
        double maxx=0;
        dp[i]++;                    //选择第i个听证会则他本身期望为1
        e=z[i].s+z[i].a;            //最早结束时间
        p2=z[i].s+z[i].b;            //p2为该听证会进行时间我们还未处理的最晚时刻(初始化为最晚结束时间)
        int m=z[i].b-z[i].a+1;        //听证会进行时间分为m段(每段长度)
        while (p2>=e)                //如果该听证会我们尚未处理完
        {
            while(k>i)                //k为开始时间晚于我们未处理的时刻的最早听证会
            {
                if (z[k].s<p2)
                    break;
                if (dp[k]>maxx)        //更新这个时刻我们能取的最优解
                    maxx=dp[k];        
                k--;
            }
            p1=e>z[k].s+1?e:z[k].s+1;    //将最优解不需要更新的时刻合并处理(不处理会TLE)(因为如果这一段时刻没有开始的听证会,则最优解不变)
            dp[i]+=maxx*(p2-p1+1)/m;    
            p2=p1-1;                    //更新p2
        }
    }
    double maxx=0;
    for (i=0;i<n;i++)
        if (dp[i]>maxx)
            maxx=dp[i];
    printf("%.16f",maxx);
    return 0;
}

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值