zoj 1338 Up and Down Sequences

原创 2012年03月23日 09:03:11
#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 || poj 1492 Up and Down Sequences

模拟~! 好久没有1A了。。。泪奔。。 这题好早以前看过,因为太长了所以就放过去了 = =。。今天小盆友问我这题的题意,我就又看了下。。。索性给做了。。跟小朋友说,咱俩比比谁先做出来吧~嘻嘻。。。我先...

ZOJ 1338 Up and Down Sequences

Up and Down Sequences Time Limit: 2 Seconds      Memory Limit: 65536 KB The quality of pseudo ...

poj 1492 Up and Down Sequences 模拟计数

水题,直接贴代码。 //poj 1492 //sep9 #include using namespace std; int a[64]; int n; void deal() { int up...
  • sepNINE
  • sepNINE
  • 2015年01月07日 00:39
  • 831

【IndiaHacks 2016 - Online Edition (Div 1 + Div 2) ErrichtoC】【脑洞 好题 讨论?NO!暴力】Bear and Up-Down 多少种一次交

Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes ...

硬件相关——Pull-up and Pull-down Resistors

硬件相关——Pull-up and Pull-down Resistors

Codeforces 653C Bear and Up-Down【暴力+思维】题目还不错~

C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes inp...

4-1 Percolate Up and Down

4-1 Percolate Up and Down   (7分) Write the routines to do a "percolate up" and a "percolate d...

Codeforces 653C - Bear and Up-Down 暴力

C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st...

Top-down and bottom-up parser

Possible Approaches The syntax analysis phase of a compiler verifies that the sequence of tokens ex...
  • lhq9220
  • lhq9220
  • 2011年06月26日 23:40
  • 1187

Up and down the scanner.zip

  • 2014年05月16日 17:46
  • 2KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:zoj 1338 Up and Down Sequences
举报原因:
原因补充:

(最多只允许输入30个字)