HDU - 1008ACM
2014-12-25 02:14
169 查看
这个题有点简单,代码只用1分钟~
主要是看清,每行的第一个数字是说明当前用例有几个数字,而不是楼层。
//
// main.cpp
// Elevator
//
// Created by Alps on 14/12/25.
// Copyright (c) 2014年 chen. All rights reserved.
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int a,b = 0,c = 0;
int i;
int time = 0;
while (1) {
scanf("%d", &a);
if (0 == a) {
break;
}
for (i = 0; i < a; i++) {
scanf("%d",&b);
if (b > c) {
time += (b-c)*6+5;
}else{
time += (c-b)*4+5;
}
c = b;
}
printf("%d\n",time);
time = 0;
c = 0;
}
return 0;
}
主要是看清,每行的第一个数字是说明当前用例有几个数字,而不是楼层。
//
// main.cpp
// Elevator
//
// Created by Alps on 14/12/25.
// Copyright (c) 2014年 chen. All rights reserved.
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int a,b = 0,c = 0;
int i;
int time = 0;
while (1) {
scanf("%d", &a);
if (0 == a) {
break;
}
for (i = 0; i < a; i++) {
scanf("%d",&b);
if (b > c) {
time += (b-c)*6+5;
}else{
time += (c-b)*4+5;
}
c = b;
}
printf("%d\n",time);
time = 0;
c = 0;
}
return 0;
}
相关文章推荐
- hdu 2018 母牛的故事
- HDU 2047 - 阿牛的EOF牛肉串
- HDU 1754 线段树裸题
- hdu 3953 I'll play a trick on you (递推)
- hdu 1890 —— Splay Tree模板
- Hdu 4487 Maximum Random Walk
- hdu-3342-Legal or Not--拓扑排序//两种解法
- hdu 1114 Piggy-Bank
- hdu 1698 - Just a Hook(线段树)
- hdu 3555 数位dp模板题
- hdu2502 月之数
- hdu 4301(基本dp)
- HDU 4917 Permutation
- HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online
- hdu 4602 Partition (概率方法)
- HDU 1023 -- Train Problem II (卡特兰 Java大数)
- HDU 4405 Aeroplane chess 概率dp
- hdu 5249 元素插入、删除找中值
- (bc #45) A - Dylans loves numbers (hdu 5272)
- HDU 3062 Party (2-SAT模板题)