【CodeForces - 1624B】Make AP (简单找规律&详解)

Make AP

CodeForces - 1624B

Polycarp has 33 positive integers aa, bb and cc. He can perform the following operation exactly once.

  • Choose a positive integer mm and multiply exactly one of the integers aa, bb or cc by mm.

Can Polycarp make it so that after performing the operation, the sequence of three numbers aa, bb, cc (in this order) forms an arithmetic progression? Note that you cannot change the order of aa, bb and cc.

Formally, a sequence x_1, x_2, \dots, x_nx1​,x2​,…,xn​ is called an arithmetic progression (AP) if there exists a number dd (called "common difference") such that x_{i+1}=x_i+dxi+1​=xi​+d for all ii from 11 to n-1n−1. In this problem, n=3n=3.

For example, the following sequences are AP: [5, 10, 15][5,10,15], [3, 2, 1][3,2,1], [1, 1, 1][1,1,1], and [13, 10, 7][13,10,7]. The following sequences are not AP: [1, 2, 4][1,2,4], [0, 1, 0][0,1,0] and [1, 3, 2][1,3,2].

You need to answer tt independent test cases.

Input

The first line contains the number tt (1 \le t \le 10^41≤t≤104) — the number of test cases.

Each of the following tt lines contains 33 integers aa, bb, cc (1 \le a, b, c \le 10^81≤a,b,c≤108).

Output

For each test case print "YES" (without quotes) if Polycarp can choose a positive integer mm and multiply exactly one of the integers aa, bb or cc by mm to make [a, b, c][a,b,c] be an arithmetic progression. Print "NO" (without quotes) otherwise.

You can print YES and NO in any (upper or lower) case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).

Sample 1

InputcopyOutputcopy
11
10 5 30
30 5 10
1 2 3
1 6 3
2 6 3
1 1 1
1 1 2
1 1 3
1 100000000 1
2 1 1
1 2 2
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES

Note

In the first and second test cases, you can choose the number m=4m=4 and multiply the second number (b=5b=5) by 44.

In the first test case the resulting sequence will be [10, 20, 30][10,20,30]. This is an AP with a difference d=10d=10.

In the second test case the resulting sequence will be [30, 20, 10][30,20,10]. This is an AP with a difference d=-10d=−10.

In the third test case, you can choose m=1m=1 and multiply any number by 11. The resulting sequence will be [1, 2, 3][1,2,3]. This is an AP with a difference d=1d=1.

In the fourth test case, you can choose m=9m=9 and multiply the first number (a=1a=1) by 99. The resulting sequence will be [9, 6, 3][9,6,3]. This is an AP with a difference d=-3d=−3.

In the fifth test case, it is impossible to make an AP.

题意描述:给多组数据,分别为a,b,c 看某个数乘以一个整数可不可以使它们三个组成等差数列,可以输出YES,否则NO

解题思路:根据等差数列 我们可以知道 a+c=2*b;然后我们如果要变那个数就变化公式对那个数取余,看是否为0 ,如果可以整除就YES,否则NO

易错分析:我刚开始用了一个if 对a,b,c三种情况取模,我当时想的是只要有一个满足就可以了: if((a+c)%(2*b)==0 || (b*2-a)%c==0 || (b*2-c)%a==0) //分别改变 b、c、a

但是会有我们本来应该变b的值不能满足公式,但是a、c可以满足的。

拿个例子2 1 1 我们应该让b=1.5才能成等差数列,也就是1*1.5 此时不满足题意。

但是如果用(2*b-a)%c==0判断就可以通过。因为 2-2=0 直接就结果为0了。

所以我们需要先限制改变b 还是改变a、c,然后再根据情况去判断。

AC

#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		if(a+c>2*b)//变b 
		{
			if((a+c)%(2*b)==0)
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl; 
		}
			
		else //变a、c 
		{
			if((b*2-a)%c==0||(b*2-c)%a==0)
				cout<<"YES"<<endl;
			else
				cout<<"NO"<<endl;
		}
		
	}
	return 0;
 } 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值