题解 P1897 【电梯里的爱情 】
这题可以用队列的思想来做
是不是有点复杂了
首先,我们要给数据先排个列,用sort就OK了,
应该不会有人不会吧
然后嘞我们求队首与前一个数的差
如果相等我们的时间就直接加1
否则就要用这个差去乘6再加5加1
因为上一楼要6秒,开个门要5秒,走个人要1秒
然后队首出队。直到队列空了,就停止,再加上最后一个出队的数乘4
因为还要回到0楼
最后送上AC代码,好人做到底,再帮忙点个赞呗
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
long long n,a[1000010],front,t=0,s,l=0;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
front=1;
sort(a+1,a+1+n);
while(front!=n+1)
{
int c=a[front]-a[front-1];
if(c==0)
{
t+=1;
}
else
{
t+=(c*6+6);
}
front++;
}
t+=a[front-1]*4;
cout<<t;
return 0;
}