poj 1492 Up and Down Sequences 模拟计数

水题,直接贴代码。

//poj 1492
//sep9
#include <iostream>
using namespace std;
int a[64];
int n;
void deal()
{
	int up=0,down=0,upSum=0,downSum=0;
	int i,j;
	for(i=1;i<n;){
		if(a[i]<a[i+1]){
			++up;
			for(j=i+1;j<=n;++j)
				if(a[j-1]<=a[j])
					++upSum;
				else
					break;
		}
		if(a[i]>a[i+1]){
			++down;
			for(j=i+1;j<=n;++j)
				if(a[j-1]>=a[j])
					++downSum;
				else
					break;
		}
		if(a[i]==a[i+1]){
			int flag=0;
			for(j=i+1;j<=n;++j)
				if(a[j-1]<a[j]){
					flag=1;
					break;
				}
				else if(a[j-1]>a[j]){
					flag=-1;
					break;
				}
			if(flag==0)
				break;
			if(flag==1){
				++up;
				for(j=i+1;j<=n;++j)
					if(a[j-1]<=a[j])
						++upSum;
					else
						break;
			}
			if(flag==-1){
				++down;
				for(j=i+1;j<=n;++j)
					if(a[j-1]>=a[j])
						++downSum;
					else
						break;
			}
		}
		i=j-1;
	}
	double f1,f2;
	if(upSum==0)
		f1=0;
	else
		f1=upSum*1.0/up;
	if(downSum==0)
		f2=0;
	else
		f2=downSum*1.0/down;
	printf("Nr values = %d:  %.6lf %.6lf\n",n,f1,f2);
}

int main()
{
	n=0;
	while(1){
		int x;
		scanf("%d",&x);
		if(x==0){
			if(n==0)
				break;
			deal();
			n=0;
		}
		else
			a[++n]=x;
	}
	return 0;
} 
时间: 2024-10-31 18:59:39

poj 1492 Up and Down Sequences 模拟计数的相关文章

POJ 1068--Parencodings--括号逆匹配(模拟)

Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19655   Accepted: 11870 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn

POJ 3087 Shuffle&#39;m Up (模拟)

Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5850   Accepted: 2744 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of

POJ 3623 Best Cow Line, Gold(模拟)

题意  给你一个字符序列   你每次可以从它的头部或尾部拿出一个字符组成一个新的字符序列   输出这样做能达到的最小的字符序列   每行最多输出80个字符(开始被这个坑了好久) 直接模拟就行  哪边小就选哪边  相等就往内看 #include<cstdio> #include<iostream> #include<string> using namespace std; const int N = 30010; int main() { char s[N][2]; in

POJ 3750,小孩报数问题,模拟约瑟夫问题

小孩报数问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4649 Description 有N个小孩围成一圈,给他们从1开始依次编号,现指定从第W个开始报数,报到第S个时,该小孩出列,然后从下一个小孩开始报数,仍是报到S个出列,如此重复下去,直到所有的小孩都出列(总人数不足S个时将循环报数),求小孩出列的顺序. Input 第一行输入小孩的人数N(N<=64) 接下来每行输入一个小孩

poj 3087 Shuffle&#39;m Up (模拟搜索)

Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5953   Accepted: 2796 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of

poj 3117 Friends or Enemies?(模拟)

题目链接:http://poj.org/problem?id=3119 Friends or Enemies? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 431   Accepted: 177 Description A determined army on a certain border decided to enumerate the coordinates in its patrol in a way to

POJ 3087 Shuffle&#39;m Up(模拟)

题意   给两堆牌s1,s2交给你洗 每堆有c张  每次洗牌得到s12  其中s2的最下面一张在s12的最下面一张然后按顺序一张s1一张s2  洗好之后可以把s12下面的c张做s1   上面的c张做s2  求多少次洗牌之后可以得到输入给你的串s  不能得到输出-1 简单模拟  s1+s2!=s就一直洗牌   如果回到初始状态都没得到s就不会得到s了   得到s就可以输出洗牌次数了 #include<iostream> #include<string> using namespace

POJ 3282 Ferry Loading IV(模拟)

Description Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by the river's current. Cars drive onto the ferry from one end, the ferry cross

POJ 1696 Space Ant --枚举,模拟,贪心,几何

题意: 有很多点,从最右下角的点开始走起,初始方向水平向右,然后以后每步只能向左边走,问最多能走多少个点. 解法: 贪心的搞的话,肯定每次选左边的与它夹角最小的点,然后走过去. 然后就是相当于模拟地去选点,然后计数,然后走过去.这题就这么搞定了. 我这里用了set和vector. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include &