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;
  }
}
相关文章
|
数据采集 XML JSON
获取携程网站上指定景点的用户评论数据
获取携程网站上指定景点的用户评论数据
1999 0
xltd文件怎么打开?教你xltd格式文件打开方法
xltd文件怎么打开?教你xltd格式文件打开方法
5001 0
|
3月前
|
人工智能
被AI裁掉的35岁设计师,0成本开了家一人公司,月入数万还出海了
35岁品牌设计师被AI裁员后,0成本创办一人公司:用AI独立完成短剧承制,月入数万,作品出海新法。站对杭州上城区政策风口——亿元补贴、算力券、免费工位,实现“作品先行、B端变现、城市赋能”。真正启示:被冲击不可怕,不换工具才可怕。(239字)
|
5月前
|
安全 UED
AIGC 安全治理的三道防线:输入、输出与运营闭环
AIGC 安全治理可以按三道防线落地:输入检测用于识别提示词注入、越狱和高风险意图;输出审核用于识别生成内容中的违规、侵权、误导和多模态风险;运营闭环用于沉淀日志、复核结论、样本回流和策略迭代。三者协同,才能支撑生产级 AIGC 应用稳定运行。
|
5月前
|
边缘计算 安全 开发者
「ESA X 云大使邀请有礼」活动圆满收官|获奖名单正式公示
阿里云边缘安全加速(ESA)「云大使邀请有礼」活动已于2026年6月30日24时圆满结束。感谢全国开发者热情参与,共同助力ESA生态繁荣。现公示获奖名单:一等奖iPad Air、二等奖雷蛇键盘等奖品,实物奖需7日内填写收货地址,虚拟卡将邮件发放。ESA免费版永久可用,欢迎持续体验!
|
6月前
|
人工智能 搜索推荐 机器人
GEO优化的诊断与调优:解析AI时代内容策略
本文系统解析生成式引擎优化(GEO)——AI时代SEO的演进形态,聚焦内容在AI理解、信任与重构中的新挑战。依托于磊老师首创的“两大核心+四轮驱动”方法论,提供诊断盲区、量化评估与实操调整的完整路径,助力内容真正被AI看见、信任并引用。
381 0
|
6月前
|
人工智能 缓存 安全
刚刚 Claude Code 源码泄露!我扒出了 11 个隐藏秘密
大家好,我是程序员鱼皮 👨🏻‍💻。 堪称全球最强的 AI 编程工具 Claude Code 的 50 多万行源码泄露了!一家以 AI 安全著称的公司,自己却在代码发布环节翻了车。 针对这件事,我只想说两个字: 感谢! 这份源码对学技术的同学来说简直是宝藏资源啊,过年了过年了! 那 Claude Code 源码具体是怎么泄露的?源码里有哪些精妙的设计?为什么它能做到 AI 编程工具的天花板?
568 0
|
9月前
|
存储 监控 Java
分布式调用三大基石:超时、重试、幂等的架构级落地规范与全场景避坑指南
本文深入解析分布式调用稳定性三大基石:超时(设生死线、分层预算、中断执行)、重试(限次数/退避/幂等前提)与幂等(唯一键、原子校验、结果复用),结合全链路透传、AOP实现及高频避坑指南,提供可落地的架构级协同方案。
816 6
|
Unix 编译器 C语言
C 编译器
C 编译器。
656 4