Codeforces Round #665 (Div. 2)

传送门

A

找规律,上来差点找吐了

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << x << '\n'
using namespace std;
 
int main(){
    int l;
    int n,k;
    scanf("%d",&l);
    while(l--){
        scanf("%d%d",&n,&k);
        if(n > k){
            if((n-k)%2 == 0)
                printf("0\n");
            else
                printf("1\n");
        }
        else{
            printf("%d\n",k-n);
        }
    }
    return 0;
}

B

六个数字互相减就行了,想一下就出来了,挺简单的

忘记乘2了,wa了几发,难受

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << x << '\n'
using namespace std;
 
int main(){
    int l;
    int x1,y1,z1;
    int x2,y2,z2;
    scanf("%d",&l);
    while(l--){
        scanf("%d%d%d",&x1,&y1,&z1);
        scanf("%d%d%d",&x2,&y2,&z2);
        int l = min(z1,y2);
        long long ans = l * 2;
        y2 -= l;
        z1 -= l;
        long long z,x;
        y1 -= (x2 + y2);
        z2 -= (z1 + x1);
        if(y1 >= 0)
            ans -= y1 * 2;
        printf("%lld\n",ans);
    }
    return 0;
}

y1 -= (x2 + y2) 和 z2 -= (z1 + x1) 是 相等的,

因为题目中保证 x1+y1+z1 = x2+y2+z2 > 0

C

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << x << '\n'
using namespace std;
 
const int N = 100100;
 
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
 
int z[N], x[N];
 
int main(){
    int _;
    int n;
    scanf("%d",&_);
    while(_ --){
        scanf("%d",&n);
        int minl = 1e9+7;
        for(int i = 1;i <= n;i ++ ){
            scanf("%d",&z[i]);
            x[i] = z[i];
            if(minl > z[i])
                minl = z[i];
        }
        sort(z+1, z + n + 1);
 
        int k = minl;
 
        for(int i = n;i >= 1;i -- ){
            if(z[i]!= x[i]){
                k = gcd(x[i] , k );
            }
        }
        if(k != minl)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

如果按照一下的方法写的话是不对的,因为
2 12 8 的话 8 和12 是不能直接交换的,应该 8 12 先后和 2 进行交换

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define inf 0x3f3f3f3f
#define debug(x) cerr << #x << x << '\n'
using namespace std;
 
const int N = 100100;
 
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
struct node{
    int zz, id;
}z[N];
 
bool cmp(node a,node b){
    if(a.zz != b.zz)
        return a.zz < b.zz;
}
 
 
 
int main(){
    int _;
    int n;
    scanf("%d",&_);
    while(_ --){
        scanf("%d",&n);
        int minl = 1e9+7;
        for(int i = 1;i <= n;i ++ ){
            scanf("%d",&z[i].zz);
            z[i].id = i;
            if(minl > z[i].zz)
                minl = z[i].zz;
        }
        sort(z+1, z + n + 1, cmp);
 
        int k = 0;
        for(int i = n;i >= 1;i -- ){
            if(z[i].id!= i){
                if(gcd(z[i].zz, z[z[i].id].zz) == minl){
                    int t = z[i].zz;
                    int ip = z[i].id;
                    int tt = z[ip].zz;
                    int ipp = z[ip].id;
                    z[ip].zz = t;
                    z[ip].id = ip;
                    z[i].zz = tt;
                    z[i].id = ipp;
                }
                else{
                    k = 1;
                    break;
                }
            }
        }
        if(k)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值