AtCoder Beginner Contest 042

AtCoder Beginner Contest 042

A - Iroha and Haiku (ABC Edition)

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;

signed main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

B - Iroha Loves Strings (ABC Edition)

题意:

题解:

代码:

#include <bits/stdc++.h>

#define int long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
}

int const MAXN = 2e5 + 10;
int n, m, T;
string s[1000];

signed main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> s[i];
    sort(s, s + n);
    string res = "";
    for (int i = 0; i < n; ++i) res += s[i];
    cout << res;
    return 0;
}

C - Iroha’s Obsession

题意:

题解:

代码:

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

int n, m, tmp;
bool t[15];

bool chk(int x) { // check
	while (x) {
    	int CoL = x % 10;
    	if (t[CoL]) return false;
    	x /= 10;
    }
    return 1;
}

int main() {
	scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
    	scanf("%d", &tmp);
        t[tmp] = 1;
    }
    
    while (n) {
    	if (chk(n)) {printf("%d\n", n); break;}
        n++;
    }
	return 0;
}

D - Iroha and a Grid

题意:

题解:

代码:

/*
本题的a,b数据量为[1,
1e5],可以预处理出阶乘,fact[a]表示a的阶乘,infact[a]表示a!的逆元 那么    fact[i] =
(LL)fact[i - 1] * i % mod; infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod)
% mod; 每次询问是可以按照公式fact[a] * infact[b] * infact[a -
b]来O(1)计算出C[a][b]
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int const N = 2e5 + 10, mod = 1e9 + 7;
int fact[N], infact[N];
int n, m;

LL qmi(LL a, LL k, LL p) {
    LL res = 1;
    while (k) {
        if (k & 1) res = res * a % p;
        k >>= 1;
        a = a * a % p;
    }
    return res;
}

// 预处理
void init() {
    fact[0] = infact[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = (LL)fact[i - 1] * i % mod;
        infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod) % mod;
    }
}

int cnm(int x, int y) {
    return (LL)fact[x] * infact[y] % mod * infact[x - y] % mod;
}

int get(int i, int j, int x, int y) { return cnm(x - i + y - j, x - i); }

int main() {
    init();  // 预处理
    int a, b;
    cin >> n >> m >> a >> b;
    LL res = 0;
    for (int i = 1; i <= n - a; ++i) {
        res = (res + (LL)get(1, 1, i, b) * get(i, b + 1, n, m) % mod) % mod;
    }
    res = (res % mod + mod) % mod;
    cout << res;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值