B. Obtain Two Zeroes -Codeforces Round 77 (Div. 2)
http://codeforces.com/contest/1260/problem/B
1 second
256 megabytes
standard input
standard output
You are given two integers aa and bb. You may perform any number of operations on them (possibly zero).
During each operation you should choose any positive integer xx and set a:=a−xa:=a−x, b:=b−2xb:=b−2x or a:=a−2xa:=a−2x, b:=b−xb:=b−x. Note that you may choose different values of xx in different operations.
Is it possible to make aa and bb equal to 00 simultaneously?
Your program should answer tt independent test cases.
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Then the test cases follow, each test case is represented by one line containing two integers aa and bb for this test case (0≤a,b≤1090≤a,b≤109).
For each test case print the answer to it — YES if it is possible to make aa and bb equal to 00 simultaneously, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
3
6 9
1 1
1 2
YES
NO
YES
In the first test case of the example two operations can be used to make both aa and bb equal to zero:
- choose x=4x=4 and set a:=a−xa:=a−x, b:=b−2xb:=b−2x. Then a=6−4=2a=6−4=2, b=9−8=1b=9−8=1;
- choose x=1x=1 and set a:=a−2xa:=a−2x, b:=b−xb:=b−x. Then a=2−2=0a=2−2=0, b=1−1=0b=1−1=0.
题意:
每次给定两个数
可以对两个数进行若干次操作
每次操作在一个数上减掉x,在另一个数上减掉2x
输出是否能同时变成0
解法:
不放设两个数a、b,且 a < b
则 b > 2a 时无解(不存在 x 使得b - 2x = a - x = 0)
每次操作先让a减少2,b减少1;再让a减少1,b减少2,
这样一组操作后,两个数同时减少3,
两个数在同时减少 3n 后,能变成1 : 2的整数就可解
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10; int main()
{
int a , b , t;
cin >>t;
while(t--)
{
cin >>a >>b;
if(a>b)
{
int change = a;
a = b;
b = change;
}
if((2*a-b)<0)
{
cout <<"NO" <<endl;
continue;
}
if((2*a-b)%3)
{
cout <<"NO" <<endl;
continue;
}
else
{
cout <<"YES" <<endl;
continue;
}
}
return 0;
} /*
3 1 1 !
1 2
2 2 !
*/
B. Obtain Two Zeroes -Codeforces Round 77 (Div. 2)的更多相关文章
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- A. Remainder Codeforces Round #560 (Div. 3)
A. Remainder Codeforces Round #560 (Div. 3) You are given a huge decimal number consisting of nn dig ...
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- 虚拟机搭建CDH6详细过程_三节点为例
准备工作 一.安装虚拟机.centos 1.安装VMwareWorkstation虚拟化软件 首先我们使用VMwareWorkstation来快速的进行虚拟机的新建. 本文使用的版本为VMwareWo ...
- 分享一个异地组网软件,比扬云SD-WAN,在飞牛上使用教程
上一篇文章https://www.cnblogs.com/yingjiuzou/p/18891935分享了比杨云SD-WAN的一些产品逻辑和收费逻辑,我个人觉得是很务实很诚恳的一家企业和产品. 从这期 ...
- 转|java反射方法和使用详解
概述 反射机制是在运行时,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意个对象,都能够调用它的任意一个方法.在java中,只要给定类的名字,就可以通过反射机制来获得类的所有信息.反射是 ...
- C/C++中的volatile
C/C++中的volatile 约定 Volatile 这个话题,涉及到计算机科学多个领域多个层次的诸多细节.仅靠一篇博客,很难穷尽这些细节.因此,若不对讨论范围做一些约定,很容易就有诸多漏洞.到时误 ...
- MongoDB入门实战教程(9)
前面我们学习了如何套用常见的设计模式打造合适的模型设计,本篇我们来看看在MongoDB中如何使用索引来提高查询效率. 1 MongoDB也有索引? 在使用传统关系型数据库如MSSQL.MySQL等的时 ...
- Exceptionless 5.x 无法正常发送邮件的问题解决
你有碰到过通过docker部署Exceptionless无法发送邮件的问题吗?此解决办法适用于Exceptionless 5.x版本(如果你不想升级6.x的话). 1.问题起因 去年这个时候,得知Ex ...
- 2025年推荐6个好用的 Postman 替代工具
在软件开发和API测试领域,Postman无疑是使用最广泛的工具之一.它凭借直观的界面.强大的功能以及丰富的社区支持,多年来一直备受欢迎. 然而,随着技术的发展和用户需求的多样化,Postman也暴露 ...
- java--Spring代理模式、AOP、jdbc支持
代理模式 静态代理, 1) 代理对象,要实现与目标对象一样的接口: 2) 举例:保存用户(模拟) Dao , 直接保存 DaoProxy, 给保存方法添加事务处理 App.java public cl ...
- java--http协议
web应用目录结构 |- WebRoot 根目录 |-静态资源(html+css+javascript+images+xml) 可以直接被浏览器访问到的 |-WEB-INF 不可以直接被浏览器访问到 ...
- vuepress的markdown中引入vue单文件组件
前言 有这个需求,需要封装一些组件 在markdown中使用. 找遍官方文档发现没有,顶多也就支持可以在md里定义<script setup>将md作为一个vue组件去使用 Markdow ...