题目:包含两个零##

题意:你被给予两个数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. tomcat的catalina.out日志切割

    目前我们的日志文件catalina.out累积后非常大,部分应用的catalina.out达到几十G并且还在持续增长. 日志文件太大不便于阅读和排查问题.业务增长不断增长,日志也在不断增加,为了以后便 ...

  2. [java] 集合的架构——1张图表示

  3. Sequelize小记

    http://docs.sequelizejs.com/   官方英文 Object-Relational Mapping 增 Model.create({field1:'a', field2:'b' ...

  4. oracle:表重命名

    SQL> rename test1 to test; Table renamed. SQL> alter table test rename to test1; Table altered ...

  5. Composer依赖管理 – PHP的利器

    别再到处搜PHP类扩展包了,对于现代语言而言,包管理器基本上是标配.Java 有 Maven,Python 有 pip,Ruby 有 gem,Nodejs 有 npm.PHP 的则是 PEAR,不过 ...

  6. 扛把子组20191031-2 Beta阶段贡献分配规则

    此作业的要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9910 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 韩昊 刘信鹏 B ...

  7. github上传文件让别人下载--xdd

    一.可以下载的条件 仓库要为公开(public) 该文件不可预览或者是图片,如.rar  .gif .png .doc .pdf 等格式 二.打开文件的预览界面,如下 三.将最上面的地址复制给别人即可 ...

  8. linux常见配置文件路径

    1:/etc/sysconfig/i18n                        (语言配置文件). 2:/etc/sysconfig/network-scripts/ifcfg-eth0   ...

  9. 转载 :c# 获取net framework 版本(Environment 类)

    源链接:http://www.cnblogs.com/tobecrazy/p/3362446.html 根据自己使用情况,添加了部分备注 1.获取当前操作系统版本信息 使用Environment.OS ...

  10. P2415 集合求和(一道洛谷好题鸭)(虽然可以水过,但有必研究DP)

    此题坑点: 结果必须要用long long存,int存不下 如果想要像cout<<sum*pow(2,num-1)这样在输出时计算会错:long long在计算过程被隐式转换成了doubl ...