Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

简介: Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

A. A Variety of Operations


time limit per test


1 second


memory limit per test


256 megabytes


input


standard input


output


standard output


William has two numbers aa and bb initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer kk is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer kk)


  1. add number kk to both aa and bb, or
  2. add number kk to aa and subtract kk from bb, or
  3. add number kk to bb and subtract kk from aa.


Note that after performing operations, numbers aa and bb may become negative as well.


William wants to find out the minimal number of operations he would have to perform to make aa equal to his favorite number cc and bb equal to his second favorite number dd.


Input


Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). Description of the test cases follows.


The only line of each test case contains two integers cc and dd (0≤c,d≤109)(0≤c,d≤109), which are William's favorite numbers and which he wants aa and bb to be transformed into.


Output


For each test case output a single number, which is the minimal number of operations which William would have to perform to make aa equal to cc and bb equal to dd, or −1−1 if it is impossible to achieve this using the described operations.


Example


input


Copy

6

1 2

3 5

5 3

6 6

8 0

0 0


output

Copy

-1

2

2

1

2

0


Note


Let us demonstrate one of the suboptimal ways of getting a pair (3,5)(3,5):


  • Using an operation of the first type with k=1k=1, the current pair would be equal to (1,1)(1,1).
  • Using an operation of the third type with k=8k=8, the current pair would be equal to (−7,9)(−7,9).
  • Using an operation of the second type with k=7k=7, the current pair would be equal to (0,2)(0,2).
  • Using an operation of the first type with k=3k=3, the current pair would be equal to (3,5)(3,5).


题目就是简单模拟,-1,0,1,2;这几种情况;

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int c, d;
    cin >> c >> d;
    if ((c + d) % 2 != 0) {
      cout << "-1" << endl;
      continue;
    }
    if (c == 0 && d == 0) {
      cout << "0" << endl;
      continue;
    }
    if (c == d || c + d == 0) {
      cout << "1" << endl;
      continue;
    }
    cout << "2" << endl;
  }
}
相关文章
|
JSON 搜索推荐 Java
做了个springboot接口参数解密的工具,我给它命名为万能钥匙(已上传maven中央仓库,附详细使用说明)
更新的功能具体使用示例已经更新到博文中,请在目录中找到对应位置查看
|
9月前
|
机器学习/深度学习 算法 计算机视觉
《LSTM:视频目标跟踪中时间序列信息的高效利用者》
在视频目标跟踪中,充分利用时间序列信息以提高精度至关重要。长短期记忆网络(LSTM)凭借其独特的门控机制(遗忘门、输入门和输出门)及细胞状态,在处理时间序列数据方面表现出色。遗忘门可丢弃无关信息,输入门整合新特征,输出门筛选关键信息,有效应对目标动态变化与复杂背景干扰。结合目标检测算法如YOLO,LSTM能准确预测目标位置,实现连续稳定的跟踪。
326 14
|
机器学习/深度学习 人工智能 数据可视化
号称能打败MLP的KAN到底行不行?数学核心原理全面解析
Kolmogorov-Arnold Networks (KANs) 是一种新型神经网络架构,挑战了多层感知器(mlp)的基础,通过在权重而非节点上使用可学习的激活函数(如b样条),提高了准确性和可解释性。KANs利用Kolmogorov-Arnold表示定理,将复杂函数分解为简单函数的组合,简化了神经网络的近似过程。与mlp相比,KAN在参数量较少的情况下能达到类似或更好的性能,并能直观地可视化,增强了模型的可解释性。尽管仍需更多研究验证其优势,KAN为深度学习领域带来了新的思路。
5789 5
|
前端开发
领域驱动使用问题之领域驱动设计中聚合之间的依赖如何管理
领域驱动使用问题之领域驱动设计中聚合之间的依赖如何管理
|
存储 移动开发 安全
Android微信支付和支付宝支付快速接入
创建应用并获取APPID 开发者中心中创建您的应用,会为您生成应用唯一标识(APPID),并且可以申请开通开放产品使用权限,通过APPID您的应用才能调用开放产品的接口能力。在“我的应用”中按下图方式查看APPID。
1138 0
Android微信支付和支付宝支付快速接入
Go语言高并发实现端口扫描器
Go语言高并发实现端口扫描器
429 0
如何关闭某个端口号进程
window下关闭占用某个端口方法
856 0
如何关闭某个端口号进程
|
SQL PHP Apache
windows7 安装PHP7 本地网站搭建
2016年5月21日 18:21:12 星期六 PHP7用了vc14编译的, 因此windows要下载安装一个vc14的发行包, 只有16M   2016年6月1日 23:23:52 星期三 利用PHP自带的web服务器和对sqlite3的支持进行本地网站的搭建(不用nginx/apache 不用mysql) 1.
1110 0
|
3天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。