CF1900 B Laura and Operations 题解

发布时间 2023-11-27 13:08:32作者: Martian148

Link

CF1900 B Laura and Operations

Question

给出 \(1,2,3\) 的个数 \(a,b,c\)

可以分别减少两个不同的数,增加一个与两个数都不同的数

问,是否能经过一些操作使得 就剩下 \(1\) 或 \(2\) 或 \(3\)

Solution

先考虑 \(1,2,3\) 其实是等价的,所以我们只需要考虑把 \(2,3\) 全都变成 \(1\) 的情况就可以了

如果 \(2,3\) 的个数相同,直接全部变成 \(1\) 就好了

如果 \(2,3\) 的个数不相同,需要把多的那个和 \(1\) 变成少的那个,不妨假设 \(2\) 是少的那个,那么经过一次操作,\(a-1,b+1,c-1\) ,发现 \(b,c\) 的奇偶的对应性(同奇同偶或一奇一偶)不变,如果 \(1\) 的个数不够,就把 \(2,3\) 变成 \(1\)

所以得出结论,如果 \(2,3\) 为同奇或同偶,则可行

Code

#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int ret=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
    while(ch<='9'&&ch>='0')ret=ret*10+ch-'0',ch=getchar();
    return ret*f;
}

int check(int x,int y,int z){
    if((y^z)&1) return 0;
    return 1;  
}
void solve(){
    int a=read(),b=read(),c=read();
    int ans1=check(a,b,c),ans2=check(b,a,c),ans3=check(c,a,b);
    printf("%d %d %d\n",ans1,ans2,ans3);
    return ;
}
int main(){
    // freopen("B.in","r",stdin);
    int T=read();
    while(T--) solve();
}