杭电1008

 1 #include <iostream>
 2 #define MAX 100
 3 using namespace std;
 4 int main(){
 5     int n,no;
 6     int a[100];a[0]=0;
 7     while(cin>>n && n){
 8         int x=0,y=0,z=0,s=0,k=0;
 9         for(int i=0;i<n;i++){
10             cin>>no;
11             a[i+1]=no;
12         }
13         for(int i=0;i<n;i++){
14             if(a[i+1]>=a[i])
15                 x+=(a[i+1]-a[i])*6;
16             if(a[i+1]<a[i])
17                 y+=(a[i]-a[i+1])*4;
18         }
19         for(int i=0;i<n+1;i++){  //此处判断是否全为0,注意从0到n+1
20             if(a[i]!=0)
21                 break;
22             k++;
23         }
24         if(k==n+1) n=0;//是n+1个0
25         z=n*5;
26         s=x+y+z;
27         cout<<s<<endl;
28     }
29     return 0;
30 }

这是一道很简单的题目,但我花费的时间也不少,思维还是不够清晰,应当强加练习。

值得注意的是在while之前初始化的变量只初始化一次。

时间: 2024-09-27 17:06:34

杭电1008的相关文章

杭电 1008 Elevator

杭电ACM 2014暑期集训队--选拔安排~ Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 40905    Accepted Submission(s): 22387 Problem Description The highest building in our city has only one elevator

杭电1008 Elevator

#include <stdio.h> #include <stdlib.h> int main() { int n; int i,j; int num[101]; while(1) { int sum=0; memset(num,0,sizeof(num)); scanf("%d",&n); if(n==0) { break; } else{ num[0]=0; for(i=1;i<=n;i++) { scanf("%d",&a

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b