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的更多相关文章
随机推荐
- 使用display:flex;实现两栏布局和三栏布局
一.使用display:flex;实现两栏布局 body,div{margin:0px;padding:0px;} .flex-container{display:flex;height:300px; ...
- PCB genesis大孔加小孔(即卸力孔)实现方法
一.为什么 大孔中要加小孔(即卸力孔) 这其实跟钻刀的排屑有关了,当钻刀越大孔,排屑量也越大(当然这也得跟转速,下刀速的参数有关系),通常当钻刀越大,转速越慢,下刀速也越慢(因为要保证它的排屑通畅). ...
- Area of Polycubes
http://poj.org/problem?id=3792 题意:给出n个小正方体的中心坐标,求构成的多重小立方体的表面积.要求输入的下一个小正方体必须与之前的正方体有一个面是相交的.如果不满足条件 ...
- php的session
来源:http://blog.163.com/lgh_2002/blog/static/4401752620105246517509/ http协议是WEB服务器与客户 端(浏览器)相互通信的协议,它 ...
- 写出更好的 JavaScript 条件语句
1. 使用 Array.includes 来处理多重条件 // 条件语句 function test(fruit) { if (fruit == 'apple' || fruit == 'strawb ...
- JavaScript--编程练习1
使用JS完成一个简单的计算器功能.实现2个输入框中输入整数后,点击第三个输入框能给出2个整数的加减乘除. 提示:获取元素的值设置和获取方法为:例:赋值:document.getElementById( ...
- 高斯消元_HihoCoderOffer6_03
题目3 : 图像算子 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在图像处理的技术中,经常会用到算子与图像进行卷积运算,从而达到平滑图像或是查找边界的效果. 假设原图 ...
- reactnative(1) - RefreshControl 使用案例
'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...
- Miller Rabin 大素数测试
PS:本人第一次写随笔,写的不好请见谅. 接触MillerRabin算法大概是一年前,看到这个算法首先得为它的神奇之处大为赞叹,竟然可以通过几次随机数据的猜测就能判断出这数是否是素数,虽然说是有误差率 ...
- 【译】x86程序员手册01
Intel 80386 Reference Programmer's Manual 80386程序员参考手册 Chapter 1 -- Introduction to the 80386 第1章 - ...