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

来源:互联网 发布:数据分析的例子 编辑:程序博客网 时间:2024/04/30 18:32

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

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<algorithm>#define maxn 1000using 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;}


 

原创粉丝点击