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的更多相关文章
随机推荐
- Android属性之build.prop生成过程分析(转载)
转自: http://www.cnblogs.com/myitm/archive/2011/12/01/2271032.html 本文简要分析一下build.prop是如何生成的.Android的bu ...
- Java初级进阶中高级工程师必备技能
很多人学了javase以为自己学的已经很OK了,但是其实javase里边有很多的知识点是你不知道的,不管你找的是哪里的javase的视频,大多数是不会讲这些东西,而这些东西你平时业务又不会主动去接触, ...
- Android内存管理(7)在AS中查看内存和cpu情况
Memory and CPU monitor Android Studio provides a memory and CPU monitor view so you can more easily ...
- 关于static函数在类中的定义和使用
刷题的时候遇到了这样一个问题:平时经常使用 sort()函数, 对结构体进行排序, 但是在类中使用时会出现 这样的错误提示:“Solution::cmp”: 函数调用缺少参数列表:请使用“&S ...
- mybatis or
这两天项目用到mybatis,碰到and or的联合查询,语句像这样的 select * from table where xxx = "xxx" and (xx1="x ...
- 【转】Java 集合系列05之 LinkedList详细介绍(源码解析)和使用示例
概要 前面,我们已经学习了ArrayList,并了解了fail-fast机制.这一章我们接着学习List的实现类——LinkedList.和学习ArrayList一样,接下来呢,我们先对Linked ...
- python框架之虚拟环境的配置
在开发过程中,往往同一台电脑要开发不同的项目,不同的项目可能需要不同版本的包,为了解决这个问题就引出了虚拟环境. 配置虚拟环境: 1.安装虚拟环境: sudo pip3 install virtual ...
- html中保证中文能够正常显示
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8"/> ...
- Android 根据QQ号跳转到QQ聊天界面
从自己开发的应用中根据QQ号跳转到QQ应用的聊天界面,实现起来很方便: 即: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(" ...
- Android开发之ThreadLocal原理深入理解
[Android]ThreadLocal的定义和用途 ThreadLocal用于实现在不同的线程中存储线程私有数据的类.在多线程的环境中,当多个线程需要对某个变量进行频繁操作,同时各个线程间不需要同步 ...