zoukankan      html  css  js  c++  java
  • Codeforces 621C Wet Shark and Flowers

    题意:

    一群鲨鱼围成一圈,Wet Shark说个质数p,每个鲨鱼在一定范围内选个数,如果两个相邻的鲨鱼选的数的乘积能被p整除,则每个鲨鱼都将得到1000元,求鲨鱼们最终得到钱数的期望。

    分析:

    比赛时乱七八糟的写,一直错,重新读题才注意到题目中说的:

    If for any pair of neighbouring sharks i and j the product si·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.

    只看相邻的两条鲨鱼,所以对于每条鲨鱼,只需看他和他前一条鲨鱼的数值范围大小以及范围内p的倍数的个数,转化为概率,分两种情况考虑:

    • 两条鱼选的数都是p的倍数
    • 一条鱼选的是p的倍数,另一条不是

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<iomanip>
    using namespace std;
    const int maxn = 100005, INF=0x3fffffff;
    typedef long long ll;
    double f[maxn];
    int main (void)
    {
        int n;ll p;
        ll l,r;
        ll total = 1, cnt;
        scanf("%d%I64d",&n,&p);
        for(int i = 1; i <= n; i++){
            scanf("%I64d%I64d",&l,&r);
            cnt = r/p - l/p;
            if(l%p == 0) cnt++;
            f[i]=(double)cnt/(r - l+1);
        }
        f[0] = f[n];
        double ans = 0.0;
        for(int i = 1; i <= n; i++)
           ans += 1000*(f[i]*f[i-1] + (1-f[i])*f[i-1]+(1-f[i-1])*f[i]);
    
        printf("%.10lf
    ",(double)ans*2);
        return 0;
    }
    

    仔细读题!!别再马虎了!!心疼时间和分数。。。

  • 相关阅读:
    [转自老马的文章]用MODI OCR 21种语言
    [转老马的文章]MODI中的OCR模块
    贴片晶振的脚位方向如何区分
    晶振简介及如何使用示波器测试晶振
    Lintcode 150.买卖股票的最佳时机 II
    Lintcode 82.落单的数
    Lintcode 97.二叉树的最大深度
    Lintcode 9.Fizz Buzz 问题
    LeetCode之461. Hamming Distance
    NYOJ之题目325 zb的生日
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758835.html
Copyright © 2011-2022 走看看