第八场

CodeForces - 1288A. Deadline

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图1

Example

input

  1. 3
  2. 1 1
  3. 4 5
  4. 5 11

output

  1. YES
  2. YES
  3. NO

Note

In the first test case, Adilbek decides not to optimize the program at all, since Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图2.

In the second test case, Adilbek can spend Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图3 day optimizing the program and it will run Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图4 days. In total, he will spend Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图5 days and will fit in the limit.

In the third test case, it’s impossible to fit in the limit. For example, if Adilbek will optimize the program Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图6 days, it’ll still work Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图7 days.

题意:

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图8 有一个编程任务,总工期为 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图9 天,直接暴力完成需要 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图10 天。但他可以选择花 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图11 天进行优化,然后再花 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图12 天运行。如果可以在工期内完成则输出 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图13 不然输出 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图14

思路:

如果暴力完成天数小于工期则不需要去特地优化,不然的话需要进行优化但优化天数是不能超过 工期数(即 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图15)。

详解看代码更好理解。

  1. #include<bits/stdc++.h>
  2. #define ms(a,b) memset(a,b,sizeof a)
  3. using namespace std;
  4. typedef long long ll;
  5. const int N = 1e5 + 100;
  6. ll _, n, d, a[N], i, j;
  7. void solve() {
  8. cin >> n >> d;
  9. if (d <= n) {
  10. cout << "YES" << endl;
  11. return;
  12. }
  13. for (int x = 1; x < d && x <= n; ++x) {
  14. if ((x + ceil((float)d / (x + 1))) <= n) {//必须要先提高精度(float化)不然在除的时候会导致错误,如4/3 = 1.333 = 1发生错误
  15. cout << "YES" << endl;
  16. return;
  17. }
  18. }
  19. cout << "NO" << endl;
  20. }
  21. int main() {
  22. //freopen("in.txt", "r", stdin);
  23. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  24. cin >> _; while (_--) solve();
  25. }

CodeForces - 1288B. Yet Another Meme Problem

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图16

input

  1. 3
  2. 1 11
  3. 4 2
  4. 191 31415926

output

  1. 1
  2. 0
  3. 1337

Note

There is only one suitable pair in the first test case: Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图17#card=math&code=a%3D1%2C%20b%3D9%20%281%2B9%2B1%E2%8B%859%3D19%29).

题目内部图片:

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图18

题意:

给定Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图19 求$ 1≤a≤A, 1≤b≤B1$ 有多少对(a,b)使Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图20#card=math&code=a%E2%8B%85b%2Ba%2Bb%3Dconc%28a%2Cb%29) 成立。

思路:

仔细分解一下所给的公式:

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图21%5C%5C%0Aa%20%20b%20%2B%20a%20%2B%20b%20%3D%20a%20%2010%5E%7B%7Cnum%7C%7D%20%2B%20b%20%5C%5C%0A%7C%20num%20%7C%20%E6%98%AFb%E7%9A%84%E5%8D%81%E8%BF%9B%E5%88%B6%E8%A1%A8%E7%A4%BA%E9%95%BF%E5%BA%A6%E3%80%82%5C%5C%0Aa%20%20b%20%2B%20a%20%3D%20a%20%2010%5E%7B%7Cnum%7C%7D%5C%5C%0Ab%20%2B%201%20%3D%2010%5E%7B%7Cnum%7C%7D%5C%5C%0A%E5%9B%A0%E6%AD%A4%EF%BC%8Cb%E6%80%BB%E6%98%AF%E7%9C%8B%E8%B5%B7%E6%9D%A5%E5%83%8F99%E2%80%A699%E3%80%82%20%E5%9B%A0%E6%AD%A4%EF%BC%8C%E7%AD%94%E6%A1%88%E6%98%AFa%20*%EF%BC%88%7C%20num%20%2B%201%20%7C%20-1%EF%BC%89%E3%80%82%0A#card=math&code=a%20%2A%20b%20%2B%20a%20%2B%20b%20%3D%20conc%28a%2Cb%29%5C%5C%0Aa%20%2A%20b%20%2B%20a%20%2B%20b%20%3D%20a%20%2A%2010%5E%7B%7Cnum%7C%7D%20%2B%20b%20%5C%5C%0A%7C%20num%20%7C%20%E6%98%AFb%E7%9A%84%E5%8D%81%E8%BF%9B%E5%88%B6%E8%A1%A8%E7%A4%BA%E9%95%BF%E5%BA%A6%E3%80%82%5C%5C%0Aa%20%2A%20b%20%2B%20a%20%3D%20a%20%2A%2010%5E%7B%7Cnum%7C%7D%5C%5C%0Ab%20%2B%201%20%3D%2010%5E%7B%7Cnum%7C%7D%5C%5C%0A%E5%9B%A0%E6%AD%A4%EF%BC%8Cb%E6%80%BB%E6%98%AF%E7%9C%8B%E8%B5%B7%E6%9D%A5%E5%83%8F99%E2%80%A699%E3%80%82%20%E5%9B%A0%E6%AD%A4%EF%BC%8C%E7%AD%94%E6%A1%88%E6%98%AFa%20%2A%EF%BC%88%7C%20num%20%2B%201%20%7C%20-1%EF%BC%89%E3%80%82%0A)

  1. #include<bits/stdc++.h>
  2. #define ms(a,b) memset(a,b,sizeof a)
  3. using namespace std;
  4. typedef long long ll;
  5. const int mod = 1e9 + 7;
  6. const int N = 1e5 + 100;
  7. ll _, n, m, a[N], i, j;
  8. void solve() {
  9. ll A, B; cin >> A >> B;
  10. ll weinum = 0, i = B;
  11. bool flag = true;
  12. while (i) {
  13. weinum++;
  14. i /= 10;
  15. }
  16. i = B;
  17. while (i) {
  18. if (i % 10 != 9) {
  19. flag = false;
  20. break;
  21. }
  22. i /= 10;
  23. }
  24. if (flag)cout << A * weinum << endl;
  25. else cout << A * (weinum - 1) << endl;
  26. }
  27. int main() {
  28. //freopen("in.txt", "r", stdin);
  29. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  30. cin >> _; while (_--) solve();
  31. }
  1. #python
  2. for t in range(int(input())):
  3. a, b = map(int, input().split())
  4. print(a * (len(str(b + 1)) - 1))

1288C - Two Arrays

组合数学问题。

让我们考虑以下顺序:

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图22

它的长度为$ 2m Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图23 1 Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图24 n $之间的整数。

我们可以通过简单的组合来找到此类序列的数量-它是与重复结合在一起的。 所以答案是

Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图25!(2m)!%2F(n%E2%88%921)!%0A#card=math&code=%5Cbegin%7Bpmatrix%7Dn%2B2m%E2%88%921%5C%5C%5C%5C2m%5Cend%7Bpmatrix%7D%20%3D%20%28n%2B2m%E2%88%921%29%21%282m%29%21%2F%28n%E2%88%921%29%21%0A)

  1. #python
  2. from math import factorial as fact
  3. mod = 10**9 + 7
  4. def C(n, k):
  5. return fact(n) // (fact(k) * fact(n - k))
  6. n, m = map(int, input().split())
  7. print(C(n + 2*m - 1, 2*m) % mod)

1288D - Minimax Problem

思路:来自CF官网

我们将使用二进制搜索来解决该问题。 假设我们想知道答案是否不少于x。
每个数组都可以由一个m位掩码表示,其中如果数组的第i个元素不少于x,则第i个位为1;如果第i个元素小于x,则第i个位为0。 如果要验证答案不小于x,则必须选择两个数组,使它们的掩码的按位或为Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图26
检查所有成对的数组太慢。 取而代之的是,我们可以将相同掩码表示的数组视为相等-这样,我们将不会有超过Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图27个不同的数组,并且可以迭代Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图28对。 总体而言,该解决方案在Educational Codeforces Round 80 A - D题题解(又是卡很久的一场比赛) - 图29下工作。

C++代码实现:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n, m;
  4. vector<vector<int> > a;
  5. int a1, a2;
  6. bool can(int mid)
  7. {
  8. vector<int> msk(1 << m, -1);
  9. for(int i = 0; i < n; i++)
  10. {
  11. int cur = 0;
  12. for(int j = 0; j < m; j++)
  13. if(a[i][j] >= mid)
  14. cur ^= (1 << j);
  15. msk[cur] = i;
  16. }
  17. if(msk[(1 << m) - 1] != -1)
  18. {
  19. a1 = a2 = msk[(1 << m) - 1];
  20. return true;
  21. }
  22. for(int i = 0; i < (1 << m); i++)
  23. for(int j = 0; j < (1 << m); j++)
  24. if(msk[i] != -1 && msk[j] != -1 && (i | j) == (1 << m) - 1)
  25. {
  26. a1 = msk[i];
  27. a2 = msk[j];
  28. return true;
  29. }
  30. return false;
  31. }
  32. int main()
  33. {
  34. scanf("%d %d", &n, &m);
  35. a.resize(n, vector<int>(m));
  36. for(int i = 0; i < n; i++)
  37. for(int j = 0; j < m; j++)
  38. scanf("%d", &a[i][j]);
  39. int lf = 0;
  40. int rg = int(1e9) + 43;
  41. while(rg - lf > 1)
  42. {
  43. int m = (lf + rg) / 2;
  44. if(can(m))
  45. lf = m;
  46. else
  47. rg = m;
  48. }
  49. assert(can(lf));
  50. printf("%d %d\n", a1 + 1, a2 + 1);
  51. }