题目:包含两个零##

题意:你被给予两个数a和b,你可以对这两个数进行操作

每次操作你可以选择任意的正整数x,可以进行a = a - x,b = b - 2x或者a = a - 2x,b = b - x两种操作

是否可以让两个整数同时变为0

输出"YES"或者"NO"

分析:可以把相同减去的第一种操作全都合并为x,第二种操作全都合并为y

可以得到a - x - 2 * y = 0,b - 2 * x - y = 0

通过这两个等式,可以得到(a + b) = 3 * x + 3 * y,说明可以被(a + b)可以被3整除

条件里存在x > 0和y > 0,通过上面的等式,可以得到3x = 2 * a - b,3y = 2 * b - a,

可以得到2 * a > b,2 * b > a,得到2a > b > a/2

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
int t; bool sentence(int a, int b)
{
if (2 * a >= b && 2 * b >= a && (a + b) % 3 == 0)
return true;
else
return false;
} int main()
{
scanf("%d", &t); while (t--)
{
int a, b;
scanf("%d%d", &a, &b); if (sentence(a, b))
{
puts("YES");
}
else {
puts("NO");
} } return 0;
}

B.Obtain Two Zeroes的更多相关文章

  1. Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes

    B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. CF-Educational Codeforces Round 77 (Rated for Div. 2)(A-E题解)

    A. Heating (水题) 题目链接 大致思路: 因为是代价是平方,所以让每一个房间的大小平均即可,即最大和最小相差不超过一. 代码: #include<bits/stdc++.h> ...

  3. Codeforces 1260 ABC

    DEF 题对于 wyh 来说过于毒瘤,十分不可做. A. Heating Description: 给定\(a,b\),将\(b\)分成至少\(a\)个正整数,使这些正整数的平方和最小. Soluti ...

  4. Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes

    题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...

  5. [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  6. [LintCode] Trailing Zeroes 末尾零的个数

    Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...

  7. 环信SDK报错处理方法obtain an updated library from the vendor, or disable bitcode for this target. for archit

    ld: '/Users/momo/Desktop/ThreeFingers/Pods/EaseMobSDKFull/EaseMobSDKFull/lib/libEaseMobClientSDK_arm ...

  8. MS SQL Could not obtain information about Windows NT group/user 'domain\login', error code 0x5. [SQLSTATE 42000] (Error 15404)

    最近碰到一个有趣的错误:海外的一台数据库服务器上某些作业偶尔会报错,报错信息如下所示: -------------------------------------------------------- ...

  9. Could not obtain information about Windows NT group/user 'xxxx\xxxx', error code 0x5

    案例描述 昨晚踢球回来,接到电话说一个系统的几个比较重要作业出错,导致系统数据有些问题.让我赶紧检查看看.检查作业日志时发现,作业报如下错误(关键信息用xxx替换) The job failed.  ...

随机推荐

  1. csp-s2019游记

    11.15D0: 复习 复习 机房里弥漫着颓废的气息,不过也是最后一个下午了 11.16D1: 五点钟爬起来,一边发抖一边去楼下买早饭 虽然平时基本不吃早饭,但考前不行 搭着同学的车去了考点,在车上重 ...

  2. 你能说说Java中Comparable和Comparator的区别吗

    之前面试中被问到这个问题,当时不屑(会)回答,下来特意查了查,整理如下. Java 中为我们提供了两种比较机制:Comparable 和 Comparator,二者都是用来实现对象的比较.排序. 下面 ...

  3. [TCP] TCP协议族的学习 and TCP协议

    1.TCP协议族这个大家庭,每个协议在OSI5层模型中所处的位子 其中,网络层里的 ICMP = Internet Control Message Protocol,即因特网控制报文协议, IGMP ...

  4. 新手如何正确安装python,视图详解

    今天教新手如何安装python,因为Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上.在Windows上写Python程序,放到Linux上也是能够运行的.学 ...

  5. 分组取topN

    假设有这样一个文件,文件内容如下 class1 class2 class1 class1 class2 class2 class1 class2 class1 class2 要求按照班级分组取出每个班 ...

  6. 一分钟带你了解下MyBatis的动态SQL!

    MyBatis的强大特性之一便是它的动态SQL,以前拼接的时候需要注意的空格.列表最后的逗号等,现在都可以不用手动处理了,MyBatis采用功能强大的基于OGNL的表达式来实现,下面主要介绍下. 一. ...

  7. hdu 1556 Color the ball (技巧 || 线段树)

    Color the ballTime Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. scipy.sparse的csc_matrix、csr_matrix与coo_matrix区别与应用(思维导图)

  9. 百度下载给的termux是个坑

    termux有两个版本,0.32以及0.64.百度提供0.32的下载,太坑爹.谷歌则是0.64的下载.32版uname -m识别为armv8l,绝对影响你进行其它linux的部署.通过atilo脚本会 ...

  10. 在linux系统下进行pip升级注意事项

    今天鼓捣爬虫的时候需要用pip安装beautifulsoup4,但是出现了错误,说我的pip版本太低,需要升级一下.刚开始我用了下面这段代码: pip install --upgrade pip 显示 ...