HDU 4505 小Q系列故事——电梯里的爱情 2013腾讯编程马拉松初赛第一场第一题

来源:互联网 发布:见兄自然知悌 编辑:程序博客网 时间:2024/05/16 09:27

题目地址:  http://acm.hdu.edu.cn/showproblem.php?pid=4505

 

这道题是一个基本题,弄清时间基本上就ok了,直接上代码。

 

代码如下:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <set>#include <map>#include <queue>using namespace std;/*freopen("input.txt",  "r", stdin);  //读数据freopen("output.txt", "w", stdout); //注释掉此句则输出到控制台*/int xh[105];int main(){int i,t,n,m,a;cin>>t;while(t--){    memset(xh,0,sizeof(xh));    cin>>n;    m=n;    int max=0;//max记录最高层    while(m--)    {        scanf("%d",&a);        if(max<a)   max=a;        xh[a]++;//a层人数+1    }    int temp=0,sum=0;//temp记录上一次电梯停的层数,sum总共需要多长时间    for(i=0;i<=max;i++)    {        while(xh[i]==0) i++;        sum+=xh[i]+(i-temp)*6+5;//下的人时间+上升的时间+开门5秒        temp=i;    }    sum+=max*4;//下降的时间    cout<<sum<<endl;}return 520;}