ACM-ICPC 2017 上海赛区ECFINAL I,M

题目链接:Chat Group  

/*
 * [链接]:https://codeforces.com/gym/101775/problem/A
 *
 * [题意]:给出n,m。问:从n个人中至少选m个人的方案数。
 *
 * [分析]: 由于n很大,m很小,因此考虑二项式,因此ans=2^n-C(n,i),i-->[0,n-1],C(n,i)递推即可。
 *
 * [tricks]:
 *
 * [时间复杂度]:
 *
 * */

#include <bits/stdc++.h>

#define  ll long long

using namespace std;

void scan() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 7;
ll fac[maxn], n, m;

ll ksm(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);//, cout.tie(0);
    scan();

    int t;
    cin >> t;
    for (ll i = 1; i < maxn; i++) fac[i] = ksm(i, mod - 2);
    for (int cas = 1; cas <= t; cas++) {
        cin >> n >> m;
        ll ans = ksm(2ll, n), tmp = 1;
        for (ll i = 0; i < m; i++) {
            ans = (ans - tmp + mod) % mod;
            tmp = (tmp * (n - i) % mod * fac[i + 1] % mod) % mod;
        }
        printf("Case #%d: %lld\n", cas, ans);
    }
    return 0;
}

题目链接:World Cup 

/*
 * [链接]:https://codeforces.com/gym/101775/problem/M
 *
 * [题意]:模拟即可。
 *
 * [分析]:
 *
 * [tricks]:
 *
 * [时间复杂度]:
 *
 * */


#include<bits/stdc++.h>

#define ll unsigned long long
using namespace std;

const long long maxn = 1e6 + 7;
ll a[maxn];
long long solve(long long cas) {
    for (long long i = 1; i <= 5; i++) cin >> a[i];
    cout << "Case #" << cas << ": ";
    int q;
    cin >> q;
    ll ans = 0;
    while (q--) {
        int x;
        cin >> x;
        if (x <= 48) ans += a[1];
        else if (x <= 56) ans += a[2];
        else if (x <= 60) ans += a[3];
        else if (x <= 62) ans += a[4];
        else ans += a[5];
    }
    cout << ans << "0000" << endl;
}

int main() {
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    long long T;
    cin >> T;
    for (long long i = 1; i <= T; i++) {
        solve(i);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值