###### zoj 1338 Up and Down Sequences
#include "iostream"
#include "stdio.h"
#include "iomanip"
using namespace std;

int main()
{
int num[30], len, i, uptimes, downtimes, midtimes, sum1, sum2;
bool up, down;
while (cin >> num[0] && num[0])
{
len = 1;
while (cin >> num[len] && num[len])
len++;

up = false, down = false;
uptimes = downtimes = midtimes = sum1 = sum2 = 0;
for (i = 1; i < len; i++)
{
if (up && num[i] >= num[i-1])
sum1++;
else if (down && num[i] <= num[i-1])
sum2++;
else if (up && num[i] < num[i-1])
{
up = false;
down = true;
downtimes++;
sum2++;
}
else if (down && num[i] > num[i-1])
{
down = false;
up = true;
uptimes++;
sum1++;
}
else if (!up && !down && num[i] > num[i-1])
{
up = true;
sum1 += midtimes;
midtimes = 0;
sum1++;
uptimes++;
}
else if (!up && !down && num[i] < num[i-1])
{
down = true;
sum2 += midtimes;
midtimes = 0;
sum2++;
downtimes++;
}
else if (!up && !down && num[i] == num[i-1])
midtimes++;
}
cout.setf(ios::fixed);
cout << "Nr values = " << len << ":  ";
if (uptimes == 0)
cout << "0.000000 ";
else
cout << setprecision(6) << double(sum1) / double (uptimes) << " ";
if (downtimes == 0)
cout << "0.000000" << endl;
else
cout << setprecision(6) << sum2 / (double)downtimes << endl;
}
}

#### ZOJ 1338 Up and Down Sequences

2013-02-10 23:32:49

#### ZOJ 1338 Up and Down Sequences

2012-08-24 10:37:50

#### zoj 1338 || poj 1492 Up and Down Sequences

2011-01-28 14:37:00

#### 浙江省第8届程序设计竞赛解题报告

2011-04-18 19:32:00

#### The 8th Zhejiang Provincial Collegiate Programming Contest / 解题报告 11.4.16

2011-04-16 18:10:00

#### UVa413 - Up and Down Sequences

2013-09-04 14:43:52

#### zoj 3965 Binary Tree Restoring（* dfs）

2017-04-25 21:47:59

#### TOJ 1101. Up and Down Sequences

2014-08-03 09:21:27

#### UVa 413 - Up and Down Sequences

2016-10-09 14:08:10

#### 信号量，和内核中函数up，down！

2012-01-03 23:11:47

## 不良信息举报

zoj 1338 Up and Down Sequences