Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
好水的题,没人做?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator