【Codeforces Round #538 (Div. 2)】A B C D E F

本文详细解析了Codeforces Round #538 (Div. 2)的六道题目,包括:A题通过特判解决葡萄分配问题;B题通过排序和标记法求解最大和及分组策略;C题讨论进制转换中的质因数问题;D题利用区间DP解决颜色块变换问题;E题结合二分查找和GCD计算最大差值;F题实现区间操作和计算欧拉函数,采用质因数分解和快速幂优化算法。
摘要由CSDN通过智能技术生成

A

题意有三个人 A 只吃绿葡萄 B 只吃绿葡萄和紫葡萄 C什么葡萄都吃

A B C 三人分别要吃 x y z个葡萄 然后给你 a b c代表 绿 紫 黑葡萄数 问你能不能满足

做法 满足的情况很少 所以初始化不满足 特判满足即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    bool flag = false;
    int sum = 0,x,y,z,a,b,c;
    scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c);
    sum = a+ b+c;
    if(a>=x)
    {
        if(b+(a-x)>=y)
        {
            if(sum - x- y >= z)
            {
                flag = true;
            }
        }
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

B

题意 给你n个数 分成k组 每组选出m个最大的 问你和最大 以及怎么分组

做法 我们将原数组排个序 把前m*k大的都标记上 然后扫一遍 你只要取到m个就可以分一组了

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
const int MAX_N = 200025;
struct node{
    int a,id;
    bool operator< (const node other) const
    {
        return a > other.a;
    }
}arr[MAX_N];
bool cmp(node a,node b)
{
    return a.id <b.id;
}
bool flag[MAX_N];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m,k;
    long long sum = 0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 1;i<=n;++i) scanf("%d",&arr[i].a),arr[i].id = i;
    sort(arr+1,arr+1+n);
    for(int i = 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值