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的更多相关文章
随机推荐
- bzoj3224 普通平衡树(splay 模板)
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 11427 Solved: 4878[Submit][St ...
- codevs1258 关路灯(☆区间dp)
1258 关路灯 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 多瑞卡得到了一份有趣而高薪的工作.每天早晨他必须 ...
- Appium + python - weixin公众号操作
from appium import webdriverfrom time import sleep desired_caps = { "platformName":"A ...
- JavaScript正则表达式(一)-常用方法
公司之前有个胖女孩说你竟然会正则? 其实正则没那么难:今天我们说说他常用的几个API. 在讲方法之前, 我们先对正则表达式做一个基本的了解: 1.正则表达式定义使用单个字符串来描述.匹配一系列符合某个 ...
- $stylus美化$
一直在用洛谷 当然不一定是洛谷 其他的网站也可以用 比如说codeforces 还是决定要美化一波 首先去找一个插件 叫做 stylus stylus下载的很多 我不想过多说明. Google和QQ浏 ...
- Python中的Map/Reduce
MapReduce是一种函数式编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)",是它们的主要思想,都是从函数 ...
- js常用操作~~~~将持续更新
1.替换多个模板变量 var s="my javascript is very poor,who can help me?" var reg=/(\w*)my(.*)is(.*)c ...
- Android基础TOP3_1:纵横屏切换
在Res下建立layout-port文件夹 为竖屏时加载的界面: 建立layout-land 文件夹 为横屏加载的界面
- animation仿进度条
animation:使用的好可以有很多酷炫效果 仿进度条效果.
- css3背景渐变色代码
从上到下 #grad { background: -webkit-linear-gradient(red, blue); background: -o-linear-gradient(red, b ...