ZOJ_3569_Dr. Zomboss's Revenge(概率期望)

Dr. Zomboss's Revenge

Time Limit: 2 Seconds       Memory Limit: 65536 KB

These days MM is interested in the final stage of Plants vs Zombies, called "Dr. Zomboss's revenge".

In this stage, MM is provided with an empty map with n rows and m columns as well as n*m plants. MM is required to fill the map with these n*m plants, which come from t different kinds.

However, the terrible fact is that, Dr. Zomboss will randomly throw a fire ball to squash MM's precious plants. A fire ball will be randomly placed on any row, squashing an entire row of plants. For instance, for a map with 5 rows and 4 columns, the possibility of squashing the first row is 1/5.

MM has been accustomed to the inevitable squashing. What he cannot bear is that many plants of the same kind might be squashed at the same time. For each kind of plants, namely the ith (1 ≤ i ≤ t) kind, if the number of plants squashed is less or equal than bi, called the bearing factor, MM won't care. However, for every additional plant (compared to bi) with the ith kind squashed, MM will get his angry value increased by ai, called argry factor.

Now, MM needs to find a way to place his plants which can minimize the expectation of this total angry value and he asked you to tell him what the minimum expectation is.

Notice that the initial angry value of MM is 0.

Input

There are multiple cases. The first line of each case contains three integers n (1 ≤ n ≤ 10), m (1 ≤ m ≤ 10), t (1 ≤ t ≤ 30), as described above. 
Each of the following t lines contains three integers discribing a kind of plant: the number of plant ci (1 ≤ ci ≤ n*m), the bearing factor bi (1 ≤ bi ≤ ci)and the angry factor ai (1 ≤ ai ≤ 100). 
We assert that the sum of ci equals to n*m. Process to the end of file.

Output

For each test case, output the minimium mathmetical expectation in a single line, rounded to 3 digits after the decimal point.

Sample Input

2 3 2
3 1 1
3 2 2

Sample Output

0.500

Hint

we put plants like
1 2 1
2 1 2
If a fire ball is thrown in the first row, the angry value = 1
If a fire ball is thrown in the second row, the angry value = 0
Hence the expactation is 0.5


题型:概率期望


题意:

       植物大战僵尸。。。

       MM有n*m个植物种在n*m的地图里,僵尸会发出一个火球,火球会随机毁掉一行,也就是说每一行被毁掉的概率是 1/n。

       一共有k种植物,MM对每一种植物都有忍耐值和怒气值,比如对第i个植物,她的忍耐值为bi,怒气值为ai。当毁掉的一行时,设这一行上的 i th植物有ci个,若是ci<=bi,MM就不会管它,若是大于bi,怒气值就会上升(ci-bi)*ai。

       问怒气值的最小期望。


分析:

       期望就是每一行的怒气值期望的和,而火球毁掉哪一行的概率是相等的,都是 1 / n,所以只需要求出最小的总怒气值,最后除以n就可以了。

       为使怒气值最小,就需要将同种植物尽量分开来放,也就是尽量做到平均,所以可以看做每一行有 ci \ n 颗ci植物。最小的总怒气就是angry +=(ci / n - bi )*  a * n.

       所以总期望就是 sum += (ci / n - bi )*  a * n /  n =(ci / n - bi )*  a .

       但是一次一次的除会存在精度误差,所以可以将“ / n ”提到外面,即:

                                                   sum += (ci - bi * n )*  a; 

                                                   ans = sum / n.


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n,m,t;
    while(~scanf("%d %d %d",&n,&m,&t))
    {
        double num,b,a,sum=0;
        for(int i=0;i<t;i++)
        {
            scanf("%lf%lf%lf",&num,&b,&a);
            if((num-b*n)>0) 
                sum+=(num-b*n)*a;
        }
        printf("%.3lf\n", sum/n);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值