【数学题】2020百度之星 初赛三 HDU-6783 Discount HDU-6784 Permutation HDU-6785 Intersection

前三道数学题

1 0 0 1 题
本来应该付的钱:b * a + ( 1 - c ) * a 充的钱+折扣的钱
实际付的钱:b * a 充的钱
优惠比例:( 1 - c ) / ( b + ( 1 - c ) )
可能做题的时候还没睡醒吧。。反正是算了五六分钟。。。

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int test; scanf("%d", &test);
    while(test--){
        int n, b[105]; double c[105], ans=0;
        scanf("%d", &n);
        for(int i=0; i<n; i++) scanf("%d%lf", &b[i], &c[i]);
        for(int i=0; i<n; i++){
            double t=(1-c[i])/(b[i]+1-c[i]);
            ans=max(ans, t);
        }
        printf("%.5lf\n", ans);
    }

   // system("pause");

    return 0;
}

1 0 0 2 题
一道数学期望的题。
因为 x ∈ (0, 1],当 p > 1 的时候,是拿到了 2x 那一堆,一定不换;
当 p <= 1 时,假设不交换期望得到的金币数目为 1,
交换以后有一半概率翻倍,一半概率减半。E(X) = 0.5 * 2 + 0.5 * 0.5 = 1.25,
一定换。

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int test; scanf("%d", &test);
    while(test--){
        double p; scanf("%lf", &p);
        if(p>1.00000) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }

    //system("pause");

    return 0;
}

1 0 0 3 题
因为卡时间嘛,所以推公式就好了。
当 m == 0 时,输出为 0;
当 m >= n / 2 时,变成了完全的倒序,逆序对数最大,为 n * ( n - 1 ) / 2;
否则就依次交换 1和n,2和n-1,…,一共交换 m 对,推的过程如下(感觉推的挺麻烦的,这是第二遍的做法。第一遍忘记怎么做的了,不过我觉得注意了那个没AC掉的点也能过。。。嘤。哎算了)
在这里插入图片描述
做题的时候没考虑范围用 int 报错了,改成 long long 过的

int:-2147483648~2147483647 10^9
long long:-9223372036854775808 ~ 9223372036854775807(>10^18)
unsigned long long的最大值:18446744073709551615

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long test; scanf("%lld", &test);
    while(test--){
        long long n, m; scanf("%lld%lld", &n, &m);
        if(m==0) cout<<"0"<<endl;
        else if(m>=n/2) cout<<n*(n-1)/2<<endl;
        else{
            long long t = n*m-m*(m+1)/2 + m*(n-2*m) + m*(m-1)/2;
            cout<<t<<endl;
        }
    }

    //system("pause");

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值