《Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad)》

A:签到题,排序之后判断一下即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e6 + 5;
const LL Mod = 1e9 + 7;
#define INF 1e9
#define dbg(x) cout << "now this num is " << x << endl;
inline LL read()
{
    LL x = 0,f = 1;char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
    while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}
    return x * f;
}
int a[55],b[55];
int main()
{
    int ca;ca = read();
    while(ca--)
    {
        int n,x;n = read(),x = read();
        for(int i = 1;i <= n;++i) a[i] = read();
        for(int i = 1;i <= n;++i) b[i] = read();
        sort(a + 1,a + n + 1);
        sort(b + 1,b + n + 1,greater<int>());
        int f = 0;
        for(int i = 1;i <= n;++i) if(a[i] + b[i] > x) f = 1;
        printf("%s
",f ? "No" : "Yes");
    }
    return 0;
}
View Code

B:这题一开始没想通。

后面想了一下应该也就是各个边界的最值。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e6 + 5;
const LL Mod = 1e9 + 7;
#define INF 1e9
#define dbg(x) cout << "now this num is " << x << endl;
inline LL read()
{
    LL x = 0,f = 1;char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
    while(c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}
    return x * f;
}
int main()
{
    int ca;ca = read();
    while(ca--)
    {
        int a,b,c,d;a = read(),b = read(),c = read(),d = read();
        int ans = max(max(a + b,c + d),b + d);
        printf("%d
",ans);
    }
    return 0;
View Code

C:首先分类思考一下。

如果A < B,那么答案就是A,

如果A > B:

1.A % B != 0,答案还是A。

2.A % B == 0.

这种情况才是本题的难点,一开始觉得这个数就是1 ~ B里的最大因子,后面想了一下B~A里也有可能。

首先,如果X能整除B,那么显然X是B的倍数。

所以我们可以对B进行质因子分解,然后将某一个质因子少去一次,乘上A消去这个质因子所有次后的数

这样出来的值必定不可能是B的倍数,且尽可能大了,且是A的因子。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = 1e6+5;
const int M = 1e6+5;
const LL Mod = 1e9+7;
#define pi acos(-1)
#define INF 1e18
#define CT0 cin.tie(0),cout.tie(0)
#define IO ios::sync_with_stdio(false)
#define dbg(ax) cout << "now this num is " << ax << endl;
namespace FASTIO{
    inline LL read(){
        LL x = 0,f = 1;char c = getchar();
        while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
        while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
        return x*f;
    }
}
using namespace FASTIO;

LL quick_mi(LL a,LL b)
{
    LL re = 1;
    while(b)
    {
        if(b & 1) re = re * a;
        b >>= 1;
        a = a * a;
    }
    return re;
}
int main()
{
    int ca;ca = read();
    while(ca--)
    {
        LL p,q;p = read(),q = read();
        LL ans = 1;
        if(p < q) ans = p;
        else if(p % q != 0) ans = p;
        else
        {
            int m = sqrt(q);
            for(int i = 2;i <= m;++i)
            {
                if(q % i == 0)
                {
                    int cnt = 0;
                    while(q % i == 0) q /= i,cnt++;
                    LL ma = p;
                    while(ma % i == 0) ma /= i;
                    ans = max(ans,ma * quick_mi(i,cnt - 1));
                }
            }
            if(q > 1)
            {
                LL ma = p;
                while(ma % q == 0) ma /= q;
                ans = max(ans,ma);
            }
        } 
        printf("%lld
",ans);
    }
    system("pause");
    return 0;
}
View Code

D:先去数组进行一个排序,然后就可以证明:对于每个组合都是大的一半 的和 - 小的一半的和。

然后乘上组合方案数C(2n,n)即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = 2e5+5;
const int M = 1e6+5;
const LL Mod = 998244353;
#define pi acos(-1)
#define INF 1e18
#define CT0 cin.tie(0),cout.tie(0)
#define IO ios::sync_with_stdio(false)
#define dbg(ax) cout << "now this num is " << ax << endl;
namespace FASTIO{
    inline LL read(){
        LL x = 0,f = 1;char c = getchar();
        while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
        while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
        return x*f;
    }
}
using namespace FASTIO;

LL a[N << 1],f[N << 1];
void init()
{
    f[0] = 1;
    for(int i = 1;i < N * 2;++i) f[i] = f[i - 1] * i % Mod;
}
LL quick_mi(LL a,LL b)
{
    LL re = 1;
    while(b)
    {
        if(b & 1) re = re * a % Mod;
        a = a * a % Mod;
        b >>= 1;
    }
    return re;
}
LL C(int n,int m)
{
    return f[n] * quick_mi(f[m],Mod - 2) % Mod * quick_mi(f[n - m],Mod - 2) % Mod;
}
int main()
{
    init();
    int n;n = read();
    for(int i = 1;i <= 2 * n;++i) a[i] = read();
    sort(a + 1,a + 2 * n + 1);
    LL sum1 = 0,sum2 = 0;
    for(int i = 1;i <= n;++i) sum1 += a[i];
    for(int i = n + 1;i <= 2 * n;++i) sum2 += a[i];
    LL dis = (sum2 - sum1) % Mod;
    LL ans = dis * C(2 * n,n) % Mod;
    printf("%lld
",ans);
    system("pause");
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/zwjzwj/p/13912656.html