Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

好水的题,没人做?

Posted by KatrineYang at 2016-10-31 13:01:04 on Problem 1492
#include <iostream>
#include <stdio.h>
using namespace std;

const int MXGS = 250;
int sz[MXGS];

int main() {
	while(1){
		int dr = -1;
		int cnt = 0;
		while(1){
			int tmp;
			scanf("%d", &tmp);
			if(dr > 0) {
				sz[cnt] = dr;
				cnt++;
			}
			dr = tmp;
			if(!tmp) break;
		}
		if(!cnt) break;
		//for(int i = 0; i < cnt; i++) cout << sz[i] << " "; cout << endl;
		printf("Nr values = %d:  ", cnt);
		int upGs = 0, downGs = 0;
		int upHe = 0, downHe = 0;
		int state = 0;
		for(int i = 0; i < cnt-1; i++){
			//cout << i << endl;
			if(state==0 && sz[i] < sz[i+1]){
				state = 1;
				upGs++;
				upHe += (i+1);
				//cout << upGs << " " << upHe << endl;
			}
			else if(state==0 && sz[i] == sz[i+1]){
				continue;
			}
			else if(state==0 && sz[i] > sz[i+1]){
				state = -1;
				downGs++;
				downHe += (i+1);
			}
			else if(state==1 && sz[i] <= sz[i+1]){
				upHe++;
			}
			else if(state==1 && sz[i] > sz[i+1]){
				state = -1;
				downGs++;
				downHe++;
			}
			else if(state==-1 && sz[i] >= sz[i+1]){
				downHe++;
			}
			else if(state==-1 && sz[i] < sz[i+1]){
				state = 1;
				upGs++;
				upHe++;
			}
		}
		double upPj = upGs ? (upHe * 1.0 / upGs) : 0;
		double downPj = downGs ? (downHe * 1.0 / downGs) : 0;
		printf("%.6lf %.6lf\n", upPj, downPj);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator