zoukankan      html  css  js  c++  java
  • CF570B

    给 n,m (m <= n),求一个数 a(1<= a <=n), 使得当 c 在 1 到 n 的整数中 随机取值时 ,|c-a| < |c-m| 成立的概率最大。

    基本思路:若要使上述式子最大概率成立,则需要比较2m与n的大小关系,当2m>n时,m离n较近,此时,1~m的距离>m~n的距离,c随机取值时在1~m的概率较大,此时若需要上式满足,可以理解为c到a的距离>c到m的距离,即此时a应该选在1~m这个区间中(<m的数),同理,当2m<n时,选择>m的数

    即当2m>n时,选择m-1,当2m<n时,选择m+1

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    #define maxn 10010
    #define ll long long
    #define IL inline
    #define clear(a) memset(a,0,sizeof a)
    
    int n,m;
    
    int main()
    {
        scanf("%d%d",&n,&m);
        if(n==1&&m==1){
            printf("1");
            return 0;
        }
        if(2*m>n)printf("%d",m-1);
        else printf("%d",m+1);
        return 0;
    }
  • 相关阅读:
    ebs R12 支持IE11
    reloc: Permission denied
    3.23考试小记
    3.21考试小记
    3.20考试小记
    3.17考试小记
    3.15考试小记
    3.13考试小记
    3.12考试小记
    3.10考试小记
  • 原文地址:https://www.cnblogs.com/KGW-/p/11732886.html
Copyright © 2011-2022 走看看