Kattis - politics The Uncertainty of Politics 区间首尾相间 数学期望

在即将进行的华盛顿之行中,你需要制定策略来参加尽可能多的国会听证会。每场听证会有固定的开始时间、最短和最长可能的持续时间。你必须从头到尾参加每场听证会,不能中途进入或离开。输入包含听证会的详细信息,输出是最大预期听证会数量。通过动态规划,从后往前扫描,考虑每场听证会的最早结束到最晚结束时间内其他听证会的概率影响,以计算最优策略的预期数量。
摘要由CSDN通过智能技术生成

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 ss at which the hearing will start, and then values aa and bbwhich 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][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:

hearing

ss

aa

bb

Social media and elections

1

1

7

NASA missions

3

2

3

Oil and gas exploration

5

1

4

Hurricane recovery efforts

6

10

10

For this schedule, the optimal strategy will allow you to achieve an expected value of 2.1252.125 hearings. To achieve this, you begin by attending the NASA hearing, which starts at time 33 and ends with equal probability at either time 55 or time 66 (given the hearing length that is uniformly distributed over {2,3}{2,3}). If the NASA hearing does end at time 55 you will immediately head to the oil and gas exploration hearing, and there is a 1414 chance that hearing will end at time 66, allowing you to make yet a third hearing (about hurricane recovery efforts). If the NASA hearing instead ends at time 66, you will go straight to the hurricane hearing.

By this strategy you will attend 33 hearings 12.5% of the time and 22 hearings the other 87.5% of the time, and thus expected value of 2.1252.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.107142.10714.

Input

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

Output

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

Sample Input 1Sample Output 1
4
1 1 7
3 2 3
5 1 4
6 10 10
2.125
Sample Input 2Sample Output 2
5
1 1 7
1 1 6
3 2 3
5 1 4
6 10 10
2.29166667

 

题意:

题意:每场听证会都有一个起始时间与开会最短时间与最长时间,问最多能听几场听证会的数学期望

思路:可以发现,一场听证会后面的听证会才会影响该场的数学期望,所以我们从后往前扫描,因为存在最早完成时间和最晚完成时间,所以对于每一场听证会,它的dp[i]为参加自身的1加上在它最早结束时间到最晚结束时间内的开始的听证会的dp[j]的值乘对应的发生概率

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
const int MAXN=1e6+5;
struct node
{
    int x;
    int be;
    int en;
}a[MAXN];
double dp[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
      scanf("%d%d%d",&a[i].x,&a[i].be,&a[i].en);
    for(int i=n-1;i>=0;i--){
        int fir=a[i].x+a[i].be;// 最早的时间
        int las=a[i].x+a[i].en;// 最晚的时间
        int j=n-1,com;   //
        double maxx=0;
        dp[i]++;
        int len=las-fir+1; //得到时间段
        while(las>=fir){   //进行计算
            while(j>i){
                if(a[j].x<las)
                    break;
                maxx=max(maxx,dp[j]);  //更新这一秒的最大值
                j--;
            }
            com=max(fir,a[j].x+1);
            dp[i]+=1.0*maxx*(las-com+1)/len;     //代入
            las=com-1;
        }
    }
    double sum=0;
    for (int i=0;i<n;i++)
        sum=max(sum,dp[i]);
    printf("%f\n",sum);
    return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为一个AI语言模型,我没有感受和观点,但是我可以根据已有的信息为您生成一篇关于当代世界政治和经济的文章。 当代世界政治和经济状况十分复杂,各国间的合作与竞争交织不清,经济全球化和信息技术革命的浪潮不断推动着世界的发展。 首先,世界政治格局正在发生深刻的变化。美国作为世界上最大的经济体和超级大国,一直扮演着世界警察的角色,但是随着美国国内政治的动荡和外交政策的变化,美国的全球影响力正在逐渐下降。与此同时,中国的崛起引起了世界的关注。中国的经济实力和影响力不断扩大,中国在国际事务中的发言权也在不断提高。 其次,全球经济格局也在发生深刻变化。经济全球化的趋势愈发明显,各国之间的经济联系更加紧密,但是全球经济增长放缓、贸易摩擦和保护主义倾向的加剧,也给世界经济带来了一定的挑战和风险。此外,数字经济也成为全球经济的重要组成部分,信息技术的发展带来了新的经济增长点和商业模式。 再次,全球治理面临着诸多挑战。随着全球化和信息技术的发展,各国间的合作和竞争变得更加复杂。国际组织和机制的作用也面临新的考验。同时,全球治理也面临着气候变化、恐怖主义、难民危机等全球性问题的挑战。 综上所述,当代世界政治和经济面临着巨大的挑战和机遇。各国需要加强合作,推动全球化和数字经济的发展,加强全球治理,应对全球性问题。同时,各国也需要更加注重自身的发展,提高自身的竞争力和创新能力,才能在全球经济和政治中占据更加有利的地位。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值