Hdoj 3750 guess game [two points of mathematics]

Source: Internet
Author: User

Question: Use the bipartite method to find out the mathematical expectation.

Policy.

Two mathematical methods are expected: calculate the probability of each number, multiply it with the number, and finally add all the products.

2. mathematical expectation is always equal to the mean, so it can be used as an average. (Simple and Convenient)

Code:

# Include <stdio. h> # include <string. h> int sum; void bi_sear (int n) {sum = 0; int temp, I, left, right, mid; for (I = 1; I <= N; I ++) {temp = 0; left = 1; Right = N; while (1) {++ temp; Mid = (left + right)/2; if (mid = I) {sum + = temp; break;} else if (mid <I) Left = Mid + 1; else right = mid-1 ;}}} int main () {int N; while (scanf ("% d", & n) = 1) {bi_sear (n); printf ("%. 2lf \ n ", (sum * 1.0)/n);} return 0 ;}

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3750

Hdoj 3750 guess game [two points of mathematics]

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.