其他分享
首页 > 其他分享> > 《Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad)》

《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\n",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\n",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\n",ans);
    }
    system("pause");
    return 0;
}
View Code

D:待补

 

标签:based,int,LL,Codeforces,long,ans,const,Moscow,define
来源: https://www.cnblogs.com/zwjzwj/p/13912656.html