题目大意就是电梯开门时间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;
}