CF1288(A,B,C)Round 80 (Rated for Div.2)

题目链接:https://codeforces.com/contest/1288
A. Deadline
题意:给你n,d两个数,是否满足min(n , x + [ d / ( x + 1 ) ] ) <=d,(其中0<x<n,而⌈2.4⌉=3 , ⌈2⌉=2),如果满足输出YES,否则输出NO。
思路:其实这个题中只要n/2和n/2+1满足条件即可。
AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=2e5+5;
bool cheak(int d, int x, int n)
{
    double tmp = d / (x * 1.0);
    if(tmp != d / x) tmp = d / x + 1;
    if(x - 1 + tmp <= n) return 1;
    else return 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t; cin >> t;
    while (t -- ){
        int n, d;
        cin >> n >> d;
        if(n >= d) cout << "YES" << endl;
        else {
            int x = n / 2 + 1, y = n / 2 + 2;
            if(cheak(d,x,n)||cheak(d,y,n)) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
    return 0;
}

B. Yet Another Meme Problem
题意:给您两个整数A和B,计算对(a,b)的对数,使得1≤a≤A,1≤b≤B,以及等式a⋅b+ a + b = conc(a,b) 是真的; conc(a,b)是a和b的串联(例如,conc(12,23)= 1223,conc(100,11)= 10011)。 a和b不应包含前导零。
思路:其实只要统计0~b之间有多少个像9,99,999,9999,这样全是9的数x个,答案就是a*x啦。
AC代码

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=2e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll t; cin >> t;
    while(t -- ){
        ll a, b, ans = 0;
        cin >> a >> b;
        ll x = a, y = b;
        ll res = 0, tmp = 0;
        while(y){
            tmp ++ ;
            res = res * 10 + 9;
            y /= 10;
        }
        if(res > b) tmp -- ;
        ans = x * tmp;
        cout << ans << endl;
    }
    return 0;
}

C. Two Arrays
题意:给出两个整数n和m。 计算数组对(a,b)的数量,使得:
两个数组的长度等于m;
每个数组的每个元素都是1到n(含)之间的整数;
对于从1到m的任何索引i,ai≤bi;
数组a以降序排列;
数组b以非升序排序。
结果可能非常大,您应该以1e9 + 7模数打印。
思路:啊啊啊啊,dp我还是不会,太难了,我是解不出来这个题,先把大佬的代码挂出来,之后再来细细推敲。
大佬代码

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll mod = 1e9 + 7;
ll dpa[15][1005];
ll dpb[15][1005];
int main()
{
    ll n, m;
    cin >> n >> m;
    //先对a,b进行初始化
    for(int i = 1; i <= n; i++)
    {
        dpa[1][i] = 1;
        dpb[1][i] = 1;
    }
    for(int i = 2; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= j; k++)
            {
                dpa[i][j] += dpa[i - 1][k];
                dpa[i][j] %= mod;
            }
            for(int k = j; k <= n; k++)
            {
                dpb[i][j] += dpb[i - 1][k];
                dpb[i][j] %= mod;
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j++)
        {
            ans += dpa[m][i] * dpb[m][j];
            ans %= mod;
        }
    }
    cout << ans % mod << endl;
    return 0;
}

发布了61 篇原创文章 · 获赞 0 · 访问量 991

猜你喜欢

转载自blog.csdn.net/Satur9/article/details/103994633