HDU 4505 小Q系列故事——电梯里的爱情

    题目大意就是电梯开门时间5,每下一个人1,每上一层6,每下一层4,求解最后的时间。一道简单的模拟题,首先是要对所有的人的下电梯楼层进行一个排序。然后就可以模拟了。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define maxn 1000
using namespace std;

int a[maxn];

int main()
{
    int Tcas;
    scanf("%d",&Tcas);
    
    while(Tcas--)
    {
        int n;
        scanf("%d",&n);
        
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        
        sort(a,a+n);
        
        int now = 0;
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            if(a[i]==now)
            {
                //当前在第0楼,并且是第一个人,那么就要开门
                if(i==0)  ans += 5;  
                ans++;
                continue;
            }  
                
            ans += (a[i] - now)*6;
            now = a[i];
            ans += 5; //开门
            ans++;    //出人 
        }
        
        ans += now * 4; //下楼时间 
        
        printf("%d\n",ans);
    }
    
    system("pause");
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值