HDU5753 permutation Bo (2016 multi-school training)

Source: Internet
Author: User

permutation Bo

Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 777 Accepted Submission (s): 468
Special Judge


problem DescriptionThere is sequencesh1∼hn andC1∼cn .h1∼hn is a permutation of1∼n . Particularly,h0=hn+1=0 .

We define the expression[condition] is 1 whencondition is True,is 0 whencondition Is False.

Define the functionF(H)=∑NI=1CI[HI>HI−1  a nd   hi>h i +1]

Bo has gotten the value ofc1∼< Span id= "mathjax-span-142" class= "Msubsup" >cn , and he wants to know the expected value of f (h) . InputThis problem have multi test cases (no more than A).

For each test case, the first line contains a non-negative integern(1≤n≤) , second line containsn non-negative Integer ci ( Span id= "mathjax-span-173" class= "mn" >0≤ci≤1000 ) /span> .  OutputFor each test cases print a decimal-the expectation ofF(h).

If the absolute error between your answer and the standard answer are no more than −4, your solution'll be accepted.  Sample Input43 2 4 553 5 Sample Output6.00000052.833333 title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5753 depending on the test instructions, you can consider each location's contribution to your expectations. When I is not at the end of the arrangement, there are 3! = 6 size relationships, of which 2 have contributed to the expectation, so the contribution is CI/3; When I is at both ends, there are 2! = 2 size relationships, of which 1 have contributed to the expectation, so the contribution is CI/2. (Note the case of n = = 1)
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <string>6 using namespacestd;7typedefLong Longll;8typedef unsignedLong Longull;9typedefLong Doubleld;Ten #defineMAX 1005 One  A intN; - intC[max]; - Doubleans; the voidSolve () - { -      for(intI=1; i<=n;i++) -CIN >>C[i]; +     if(n==1) -     { +Ans = c[1]; A         return; at     } -     if(n==2) -     { -Ans = (c[1]+c[2])/2.0; -         return; -     } inAns =0; -      for(intI=2; i<n;i++) toAns + = (c[i])/3.0; +ans+=c[1]/2.0; -ans+=c[n]/2.0; the } * intMain () $ {Panax Notoginseng      while(~SCANF ("%d",&N)) -     { the solve (); +printf"%.6f\n", ans); A     } the     return 0; +}
View Code

HDU5753 permutation Bo (2016 multi-school training)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.