浙江科技学院第十三届程序设计竞赛 1008-A Heavy Rainy Day【贪心思维】

A Heavy Rainy Day

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 476   Accepted Submission(s) : 124
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

As you know, Hangzhou always rains heavily, especially in Xiaoheshan area, which does annoy ACMers for a longer time. One day, N hardworking ACMers were playing League of Legends in the lab, of course not include me, while it was raining cats and dogs. Everyone wanted to come back to the department where they were living together, but no one wanted to be soaked without umbrella. Unfortunately, they only had one umbrella, which is too small to take more than two individuals. The time that everyone needs to spent to go to the department is known. If two guys came back together, it will take the longer time of this two guys. The question is the earliest time they come back to the department.

Input

The first line contains an integer T(1<=T<=20),which is the number of test cases.
For each testcase:
The first line contains one integer N ,1<=N<=1000, present N ACMers want to come back,
The second line contains N integers Si, present the time the ith ACMers need.

Output

The shortest time they need to come to the department.

Sample Input

1
4
1 2 5 10

Sample Output

17

Author

bytelin 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[10000];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=0;i<n;i++)
        {
            scanf("%d",&map[i]);
        }
        int ans=0;
        sort(map,map+n);
        while(n>=4)
        {
            if((map[0]*2+map[n-1]+map[n-2])>(map[0]+map[1]*2+map[n-1]))
            {
                ans+=map[0]+map[1]*2+map[n-1];
            }
            else
            {
                ans+=map[0]*2+map[n-1]+map[n-2];
            }
            n-=2;
        }
        if(n==3)
        {
            ans+=map[0]+map[1]+map[2];
        }
        else if(n==2)
        {
            ans+=map[1];
        }
        else
        ans+=map[0];
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据朴素贝叶斯算法,我们需要分别计算天气状况、车辆状况、是否外出这三个属性的先验概率和条件概率,并利用贝叶斯公式计算后验概率,最终选择后验概率大的结果作为预测结果。 首先,计算天气状况、车辆状况、是否外出这三个属性的先验概率: - 天气状况(Sunny/Rainy)的先验概率:$P(Sunny)=\frac{5}{10}=0.5$,$P(Rainy)=\frac{5}{10}=0.5$ - 车辆状况(working/broken)的先验概率:$P(working)=\frac{6}{10}=0.6$,$P(broken)=\frac{4}{10}=0.4$ - 是否外出(go-out/stay-home)的先验概率:$P(go-out)=\frac{5}{10}=0.5$,$P(stay-home)=\frac{5}{10}=0.5$ 接下来,计算每个属性下不同取值的条件概率: - 天气状况(Sunny/Rainy)下是否外出(go-out/stay-home)的条件概率: $$P(go-out|Sunny)=\frac{4}{5}=0.8, \quad P(stay-home|Sunny)=\frac{1}{5}=0.2$$ $$P(go-out|Rainy)=\frac{1}{5}=0.2, \quad P(stay-home|Rainy)=\frac{4}{5}=0.8$$ - 车辆状况(working/broken)下是否外出(go-out/stay-home)的条件概率: $$P(go-out|working)=\frac{5}{6}=0.833, \quad P(stay-home|working)=\frac{1}{6}=0.167$$ $$P(go-out|broken)=\frac{0}{4}=0, \quad P(stay-home|broken)=\frac{4}{4}=1$$ 根据贝叶斯公式,我们可以计算在天气状况为“Sunny”,车辆状况为“broken”时,是否外出的后验概率: $$\begin{aligned}P(go-out|Sunny,broken)&=\frac{P(Sunny|go-out)P(broken|go-out)P(go-out)}{P(Sunny)P(broken)}\\&=\frac{P(Sunny|go-out)P(broken|go-out)P(go-out)}{P(Sunny)P(broken|Sunny)P(Sunny)+P(Rainy)P(broken|Rainy)P(Rainy)}\\&=\frac{0.8*0*0.5}{0.5*0.4*0.5+0.5*0*0.5}\\&=0\end{aligned}$$ $$\begin{aligned}P(stay-home|Sunny,broken)&=\frac{P(Sunny|stay-home)P(broken|stay-home)P(stay-home)}{P(Sunny)P(broken)}\\&=\frac{P(Sunny|stay-home)P(broken|stay-home)P(stay-home)}{P(Sunny)P(broken|Sunny)P(Sunny)+P(Rainy)P(broken|Rainy)P(Rainy)}\\&=\frac{0*1*0.5}{0.5*0.4*0.5+0.5*0*0.5}\\&=0\end{aligned}$$ 因此,当天气状况为“Sunny”,车辆状况为“broken”时,预测结果为“stay-home”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值