Codeforces Round #341 (Div. 2) c. Wet Shark and Flowers (simple repulsion)

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions: There are n people sitting around in a circle, everyone can choose a number from the A[I].L to A[I].R, if the two adjacent number of products can be divided into p, then reward them a person 1000, the sum of the money to seek the expectation.

Idea: Since the expectation, the probability is obtained first. It is clear that each group of two adjacent to the value of the product can be divided by P, it is easy to know how many numbers in the interval is not divisible by P, is difficult to reverse, you can calculate the number of adjacent two how many combinations can not be divided by P, then it is easy to calculate each group can be divided by P probability, multiply 2000 is the Expectation Plus is the total expectation.

See the code for details:

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include < string> #include <vector> #include <stack> #include <bitset> #include <cstdlib> #include < cmath> #include <set> #include <list> #include <deque> #include <map> #include <queue># Define MAX (a) > (b)? ( A):(B) #define MIN (a) < (b) ( A):(B)) using namespace Std;typedef long Long ll;const double PI = ACOs ( -1.0); const double EPS = 1e-6;const int mod = 10000    00000 + 7;const int INF = 1000000000;const int MAXN = 100000 + 10;int t,n,m,p;struct node {int L, r, Num; Double P;}    A[maxn];int Main () {scanf ("%d%d", &n,&p);        for (int i=0;i<n;i++) {scanf ("%d%d", &AMP;A[I].L,&AMP;A[I].R);    A[i].num = a[i].r/p-(A[I].L-1)/p;    } double ans = 0;        for (int i=0;i<n;i++) {int J = (i + 1)% n;        Double la = a[i].l, RA = a[i].r, lb = a[j].l, RB = A[J].R; Double C1 = a[i].num, c2 = A[j].num;        A[I].P = 1.0-(double) (Ra-la + 1-c1)/(double) (Ra-la + 1) * (double) (rb-lb + 1-c2)/(double) (rb-lb + 1)        ;    Ans + = A[I].P;    } printf ("%.8f\n", ans*2000); return 0;}


Codeforces Round #341 (Div. 2) c. Wet Shark and Flowers (simple repulsion)

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.