zoukankan      html  css  js  c++  java
  • 【数学】HDU 5753 Permutation Bo

    题目链接:

      http://acm.hdu.edu.cn/showproblem.php?pid=5753

    题目大意

      两个序列h和c,h为1~n的乱序。h[0]=h[n+1]=0,[A]表示A为真则为1,假为0.

      函数f(h)=(i=1~n)∑ci[hi>hi1 && hi>hi+1]

      现在给定c的值,求f(h)的期望。

    题目思路:

      【数学】

      头尾的概率为1/2,中间的概率为1/3,直接求和。

       

     1 //
     2 //by coolxxx
     3 //
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<memory.h>
     9 #include<time.h>
    10 #include<stdio.h>
    11 #include<stdlib.h>
    12 #include<string.h>
    13 //#include<stdbool.h>
    14 #include<math.h>
    15 #define min(a,b) ((a)<(b)?(a):(b))
    16 #define max(a,b) ((a)>(b)?(a):(b))
    17 #define abs(a) ((a)>0?(a):(-(a)))
    18 #define lowbit(a) (a&(-a))
    19 #define sqr(a) ((a)*(a))
    20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    21 #define eps (1e-8)
    22 #define J 10000000
    23 #define MAX 0x7f7f7f7f
    24 #define PI 3.1415926535897
    25 #define N 1004
    26 using namespace std;
    27 typedef long long LL;
    28 int cas,cass;
    29 int n,m,lll,ans;
    30 int c[N];
    31 double s;
    32 int main()
    33 {
    34     #ifndef ONLINE_JUDGE
    35 //    freopen("1.txt","r",stdin);
    36 //    freopen("2.txt","w",stdout);
    37     #endif
    38     int i,j,l,r,x;
    39 //    for(scanf("%d",&cas);cas;cas--)
    40 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    41 //    while(~scanf("%s",s))
    42     while(~scanf("%d",&n))
    43     {
    44         s=0;
    45         for(i=1;i<=n;i++)
    46             scanf("%d",&c[i]);
    47         s+=(c[1]+c[n])/2.0;
    48         for(i=2;i<n;i++)
    49             s+=c[i]/3.0;
    50         printf("%lf
    ",s);
    51     }
    52     return 0;
    53 }
    54 /*
    55 //
    56 
    57 //
    58 */
    View Code
  • 相关阅读:
    [原创]推荐三款强大且漂亮的统计图控件
    使用ATL设计组件(VC6.0)
    COM笔记引用计数
    远程调试
    记事本2
    C++中类的多态与虚函数的使用
    Eclipse常用快捷键
    怎么在Release下调试代码
    MSDN 无法显示网页
    COM笔记接口
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5768980.html
Copyright © 2011-2022 走看看