码迷,mamicode.com
首页 > 其他好文 > 详细

【数学】HDU 5753 Permutation Bo

时间:2016-08-13 22:36:36      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:

  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\n",s);
51     }
52     return 0;
53 }
54 /*
55 //
56 
57 //
58 */
View Code

 

【数学】HDU 5753 Permutation Bo

标签:

原文地址:http://www.cnblogs.com/Coolxxx/p/5768980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!