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 ...
随机推荐
- Spring 注解之 @EnableTransactionManagement:Spring Boot 事务配置
Spring Boot 开启声明式事务支持 所有的数据访问技术都有事务处理机制,这些技术提供了API用来开启事务.提交事务以完成数据操纵,或者在发生错误的时候回滚数据.Spring支持声明式事务,这是 ...
- 「Log」2023.9.26 小记
序幕 \(\text{6:40}\):到校,整大量博客. 今天有模拟赛,发题的时候就我一个人,差点以为自己要 rk1 了. \(\text{7:30}\):开题. 发现 T1 做过,简单缩点+树直径速 ...
- 在Avalonia中使用相对单位
Avalonia目前不具备相对单位功能,要使用相对单位需要安装RelativeControl.Avalonia包 RelativeControl.Avalonia 开始使用 添加NuGet包: dot ...
- python爬虫基本学习——函数
函数 概念:编写程序时,需要某块代码多次,为了提高编写效率和代码的重用,把具有独立功能的代码块组织为一个小模块,即函数. 代码练习 ''' #函数的定义 def printinfo(): print( ...
- 假如给你1亿的Redis key,如何高效统计?
前言 有些小伙伴在工作中,可能遇到过这样的场景:老板突然要求统计Redis中所有key的数量,你随手执行了KEYS *命令,下一秒监控告警疯狂闪烁--整个Redis集群彻底卡死,线上服务大面积瘫痪. ...
- springboot的代理模式示例----面向切面编程
1.定义切面类 2.编写切面类 import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMappe ...
- 探索 JavaCV:开启计算机视觉与多媒体处理新世界
目录 JavaCV 是什么? 安装指南 有趣的 JavaCV 使用示例 录制 RTMP 直播流 捕获摄像头画面 美颜相机 引用 在当今的技术领域,计算机视觉和多媒体处理的应用愈发广泛.从视频监控到直播 ...
- DotTrace系列:8. 时间诊断之 异步代码 和 Task任务
一:背景 1. 讲故事 现如今的很多代码都是awaitasync+Task的方式,对它们进行性能洞察非常有必要,awaitasync 本质上就是将状态机塞入到 Task 的 m_continuatio ...
- 云筑集采研发团队的Scrum敏捷实践总结
Edison作为团队内部敏捷教练,这是我正式辅导的第一个Scrum Master童鞋(花名:大师兄)的敏捷迭代实践总结,在互联网公司做敏捷转型,难而正确! Scrum 是用于开发.交付和持续支持复杂产 ...
- C# vs c#判断程序是否调试模式
https://blog.csdn.net/qq_37664403/article/details/118747195 1.Debug模式,Release模式#if DEBUGConsole.Writ ...