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

第八场

CodeForces - 1288A. Deadline

Example

input

3
1 1
4 5
5 11

output

YES
YES
NO

Note

In the first test case, Adilbek decides not to optimize the program at all, since dn.

In the second test case, Adilbek can spend 1 day optimizing the program and it will run 52=3 days. In total, he will spend 4 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 2 days, it'll still work 112+1=4 days.

题意:

Adilbek 有一个编程任务,总工期为 n 天,直接暴力完成需要 d 天。但他可以选择花 x 天进行优化,然后再花 dx+1 天运行。如果可以在工期内完成则输出 YES 不然输出 NO

思路:

如果暴力完成天数小于工期则不需要去特地优化,不然的话需要进行优化但优化天数是不能超过 工期数(即 x<n)。

详解看代码更好理解。

#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
ll _, n, d, a[N], i, j;
void solve() {
	cin >> n >> d;
	if (d <= n) {
		cout << "YES" << endl;
		return;
	}
	for (int x = 1; x < d && x <= n; ++x) {
		if ((x + ceil((float)d / (x + 1))) <= n) {//必须要先提高精度(float化)不然在除的时候会导致错误,如4/3 = 1.333 = 1发生错误
			cout << "YES" << endl;
			return;
		}
	}
	cout << "NO" << endl;
}

int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> _; while (_--) solve();
}

CodeForces - 1288B. Yet Another Meme Problem

input

3
1 11
4 2
191 31415926

output

1
0
1337

Note

There is only one suitable pair in the first test case: a=1,b=9(1+9+19=19).

题目内部图片:

题意:

给定AB1aA,1bB1 有多少对(a,b)使ab+a+b=conc(a,b) 成立。

思路:

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

ab+a+b=conc(a,b)ab+a+b=a10|num|+b|num|bab+a=a10|num|b+1=10|num|b9999a|num+1|1

#include<bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;
ll _, n, m, a[N], i, j;

void solve() {
    ll A, B; cin >> A >> B;
    ll weinum = 0, i = B;
    bool flag = true;
    while (i) {
        weinum++;
        i /= 10;
    }
    i = B;
    while (i) {
        if (i % 10 != 9) {
            flag = false;
            break;
        }
        i /= 10;
    }
    if (flag)cout << A * weinum << endl;
    else cout << A * (weinum - 1) << endl;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> _; while (_--) solve();
}
#python
for t in range(int(input())):
	a, b = map(int, input().split())
	print(a * (len(str(b + 1)) - 1))

1288C - Two Arrays

组合数学问题。

让我们考虑以下顺序:

a1a2ambmbm1b1

它的长度为$ 2m 1 n $之间的整数。

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

(n+2m12m)=(n+2m1)!(2m)!/(n1)!

#python
from math import factorial as fact
mod = 10**9 + 7

def C(n, k):
	return fact(n) // (fact(k) * fact(n - k))

n, m = map(int, input().split())
print(C(n + 2*m - 1, 2*m) % mod)

1288D - Minimax Problem

思路:来自CF官网

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

C++代码实现:

#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > a;
int a1, a2;

bool can(int mid)
{
    vector<int> msk(1 << m, -1);
    for(int i = 0; i < n; i++)
    {
        int cur = 0;
        for(int j = 0; j < m; j++)
            if(a[i][j] >= mid)
                cur ^= (1 << j);
        msk[cur] = i;
    }
    if(msk[(1 << m) - 1] != -1)
    {
        a1 = a2 = msk[(1 << m) - 1];
        return true;
    }
    for(int i = 0; i < (1 << m); i++)
        for(int j = 0; j < (1 << m); j++)
            if(msk[i] != -1 && msk[j] != -1 && (i | j) == (1 << m) - 1)
            {
                a1 = msk[i];
                a2 = msk[j];
                return true;
            }
    return false;
}

int main()
{
    scanf("%d %d", &n, &m);
    a.resize(n, vector<int>(m));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    int lf = 0;
    int rg = int(1e9) + 43;
    while(rg - lf > 1)
    {
        int m = (lf + rg) / 2;
        if(can(m))
            lf = m;
        else
            rg = m;            
    }
    assert(can(lf));
    printf("%d %d\n", a1 + 1, a2 + 1);
}
posted @   RioTian  阅读(222)  评论(1编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 全程不用写代码,我用AI程序员写了一个飞机大战
点击右上角即可分享
微信分享提示

📖目录