hdu_1008_Elevator_201308191629
Elevator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34480 Accepted Submission(s): 18803
Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
Output
Print the total time on a single line for each test case.
Sample Input
1 2
3 2 3 1
0
Sample Output
17
41
//hdu-1008-Elevator
#include <stdio.h>
#include <stdlib.h>
int max[110],min[110];
int main()
{
int n;
while(scanf("%d",&n),n)
{
int i,j,k,m,sum=0;
int *a;
j=k=0;
a=(int *)malloc(n*sizeof(int));
memset(max,0,sizeof(max));
memset(min,0,sizeof(min));
scanf("%d",&a[0]);
max[a[0]]++;
for(i=1;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>a[i-1])
max[a[i]]++;
else
min[a[i]]++;
}
for(i=100;i>=0;i--)
if(max[i]>0)
{
j=i;
break;
}
for(i=0;i<=100;i++)
if(min[i]>0)
{
k=i;
break;
}
if(k==0)
k=j;
sum=j*6+(j-k)*4+n*5;
printf("%d\n",sum);
free(a);
}
return 0;
}
//理解错误,WA
//hdu-1008-Elevator-2
#include <stdio.h>
int main()
{
int n;
while(scanf("%d",&n),n)
{
int i,j,k,m,t=0,sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",&m);
if(m-t>0)
{sum+=(m-t)*6;t=m;}
else
{sum+=(t-m)*4;t=m;}
}
printf("%d\n",sum+n*5);
}
return 0;
}
//AC
hdu_1008_Elevator_201308191629的更多相关文章
随机推荐
- D. Toy Sum(cf)
http://codeforces.com/problemset/problem/405/D 题意:已知集合S={1,2,3......1000000},s=1000000,从集合S中选择n个数,X= ...
- [Swift通天遁地]七、数据与安全-(13)单元测试的各个状态和应用
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]九、拔剑吧-(8)创建气泡式页面切换效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- SpringBoot集成Swagger2 以及汉化 快速教程
(一) Swagger介绍 Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件 (二)为什么使用Swagger 在现在的开发过程中还有很大一部分公司都是以口口相传的方式来进行 ...
- NS2学习笔记(五)
对无线网络,生成nam文件要使用namtrace-all-wireless, 而不是namtrace-all: set nf [open test_1.nam w] $ns_ namtrace-all ...
- HTML--文本域,支持多行文本输入
当用户需要在表单中输入大段文字时,需要用到文本输入域. 语法: <textarea rows="行数" cols="列数">文本</texta ...
- day02_12/12/2016_bean的实例化之构造器方式
- C# 自己用到的几个参数转换方法
/// <summary> /// Method:CommandHelper /// Author:Liuyangyi /// Data:2016-05-10 /// </summa ...
- [Android]异常2-Unexpected error while executing
异常原因: 可能一>Android Studio的自动编译没有成功 解决方法有: 解决一>菜单栏里的“Build”,“Clean Project” 注:
- html5——多媒体(一)
<audio> 1.autoplay 自动播放 2.controls 是否显不默认播放控件 3.loop 循环播放 4.preload 预加载 同时设置autoplay时些属性失效 5.由 ...