poj 1492 Up and Down Sequences 類比計數,pojsequences

來源:互聯網
上載者:User

poj 1492 Up and Down Sequences 類比計數,pojsequences

水題,直接貼代碼。

//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;elsebreak;}if(a[i]>a[i+1]){++down;for(j=i+1;j<=n;++j)if(a[j-1]>=a[j])++downSum;elsebreak;}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;elsebreak;}if(flag==-1){++down;for(j=i+1;j<=n;++j)if(a[j-1]>=a[j])++downSum;elsebreak;}}i=j-1;}double f1,f2;if(upSum==0)f1=0;elsef1=upSum*1.0/up;if(downSum==0)f2=0;elsef2=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;}elsea[++n]=x;}return 0;} 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.