B - Break Standard Weight

The balance was the first mass measuring instrument invented. In its traditional form, it consists of a pivoted horizontal lever of equal length arms, called the beam, with a weighing pan, also called scale, suspended from each arm (which is the origin of the originally plural term "scales" for a weighing instrument). The unknown mass is placed in one pan, and standard masses are added to this or the other pan until the beam is as close to equilibrium as possible. The standard weights used with balances are usually labeled in mass units, which are positive integers.

With some standard weights, we can measure several special masses object exactly, whose weight are also positive integers in mass units. For example, with two standard weights 1 and 5, we can measure the object with mass 145 or 6exactly.

In the beginning of this problem, there are 2 standard weights, which masses are x and y. You have to choose a standard weight to break it into 2 parts, whose weights are also positive integers in mass units. We assume that there is no mass lost. For example, the origin standard weights are 4 and 9, if you break the second one into 4and 5, you could measure 7 special masses, which are 1, 3, 4, 5, 8, 9, 13. While if you break the first one into 1 and 3, you could measure 13special masses, which are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13! Your task is to find out the maximum number of possible special masses.

Input

There are multiple test cases. The first line of input is an integer T < 500 indicating the number of test cases. Each test case contains 2 integersx and y. 2 ≤ xy ≤ 100

Output

For each test case, output the maximum number of possible special masses.

Sample Input

2
4 9
10 10

Sample Output

13
9
 #include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<math.h>
#include<vector>
#include<deque>
#include<list>
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
using namespace std;
int f(int x,int y,int z)
{
int r[];
set<int> s;
r[]=x;
r[]=y;
r[]=z;
r[]=x+y ;
r[]=x+z;
r[]=y+z;
r[]=x-y;
r[]=y-z;
r[]=x-z;
r[]=y-x;
r[]=z-x;
r[]=z-y;
r[]=x-y-z;
r[]=x-y+z;
r[]=y-x-z;
r[]=y-x+z;
r[]=y-z+x;
r[]=z-x+y;
r[]=z-x-y;
r[]=x+y+z;
for(int i=;i<;i++)
{
if(r[i]>)
s.insert(r[i]);
}
return s.size();
} int main()
{
int t,a,b;
int maxn, sum;
scanf("%d",&t);
while(t--)
{
maxn=;
scanf("%d%d",&a,&b);
for(int i=; i<a/+; i++)
{
sum=f(i,a-i,b);
maxn=max(maxn,sum);
}
for(int i=; i<b/+; i++)
{
sum=f(a,i,b-i);
maxn=max(maxn,sum);
}
printf("%d\n",maxn);
}
return ;
}

ZCMU训练赛-B(dp/暴力)的更多相关文章

  1. ZCMU训练赛-J(循环节+字符串处理)

    J - Java Beans There are N little kids sitting in a circle, each of them are carrying some java bean ...

  2. ZCMU训练赛-H(模拟)

    H - Hard to Play   MightyHorse is playing a music game called osu!. After playing for several months ...

  3. ZCMU训练赛-A(模拟)

    A - Applications https://vjudge.net/contest/174208#overview Recently, the ACM/ICPC team of Marjar Un ...

  4. HDU6578 2019HDU多校训练赛第一场 1001 (dp)

    HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...

  5. 10.0.0.55_12-16训练赛部分writeup

    0x1 - MISC MISC100 一张帅行的照片 目测是图片隐写,但是binwalk并没有出来,应该是对文件头进行了修改 010editor查看一下,发现在jpg文件尾之后还有大量的数据 而且在灰 ...

  6. 7.30 正睿暑期集训营 A班训练赛

    目录 2018.7.30 正睿暑期集训营 A班训练赛 T1 A.蔡老板分果子(Hash) T2 B.蔡老板送外卖(并查集 最小生成树) T3 C.蔡老板学数学(DP NTT) 考试代码 T2 T3 2 ...

  7. HDU6579 2019HDU多校训练赛第一场1002 (线性基)

    HDU6579 2019HDU多校训练赛第一场1002 (线性基) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题意: 两种操作 1.在序列末 ...

  8. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  9. Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)

    Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...

随机推荐

  1. window+kafka

    window环境搭建zookeeper,kafka集群 为了演示集群的效果,这里准备一台虚拟机(window 7),在虚拟机中搭建了单IP多节点的zookeeper集群(多IP节点的也是同理的),并且 ...

  2. [转载] Win7下MATLAB 7.0下载地址和详细安装

    移步http://blog.csdn.net/feecooling/article/details/7525140 MATLAB中文手册命令汇总http://wenku.baidu.com/view/ ...

  3. LeetCode--Factorial Trailing Zeroes(注意)

    Given an integer n, return the number of trailing zeroes in n!. 问题描述:给出一个正整数n,计算n!结构后面有几个0.要求:在多项式时间 ...

  4. HDU 4776 Ants(Trie+优先队列)

    Ants Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total S ...

  5. 继承spring的validator接口,实现对数据的校验

    在org.springframework.validation这个包中提供了一些对数据校验的方法,其中Validator接口是其中的一个. 现在用Validator接口,完成对数据的校验. 第一步:先 ...

  6. gitlab迁移升级

    一.迁移步骤 1.首先安装最新版本gitlab(gitlab7.2安装) 2.停止旧版本gitlab服务 3.将旧的项目文件完整导入新的gitlab bundle exec rake gitlab:i ...

  7. Maven 标准目录结构

    Maven 标准目录结构 好的目录结构可以使开发人员更容易理解项目,为以后的维护工作也打下良好的基础.Maven2根据业界公认的最佳目录结构,为开发者提供了缺省的标准目录模板.Maven2的标准目录结 ...

  8. npm安装node-sass失败,EACCES: permission denied

    增加--unsafe-perm,即 sudo npm install node-sass --unsafe-perm --save-dev 成功安装node-sass

  9. 如何优雅地使用minicom

    minicom简介 安装 minicom是linux下一款常用的串口调试工具.ubuntu环境下,使用如下命令安装 sudo apt-get install minicom 配置 使用前需要进行配置, ...

  10. MSP432P401R时钟入门

    拿到msp432的板子差不多一年了,刚刚进行了开机点亮LED工程:         首先是msp432的时钟模块(CS),个人理解msp432最特色的功能应该是超低功耗和高性能的组合.432系列的时钟 ...