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. Mac Java配置JAVA——HOME

    命令行中输入:  export JAVA_HOME=$(/usr/libexec/java_home) 

  2. C++——类继承以及类初始化顺序

    对于类以及类继承, 几个主要的问题:1) 继承方式: public/protected/private继承. 这是c++搞的, 实际上继承方式是一种允许子类控制的思想. 子类通过public继承, 可 ...

  3. 洛谷P1546 最短网络 Agri-Net

    P1546 最短网络 Agri-Net 526通过 959提交 题目提供者JOHNKRAM 标签图论贪心USACO 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 50分C++代码,求解 请指 ...

  4. hbase vs mongodb

    1.HBase依赖于HDFS,HBase按照列族将数据存储在不同的hdfs文件中:MongoDB直接存储在本地磁盘中,MongoDB不分列,整个文档都存储在一个(或者说一组)文件中 (存储) 2.Mo ...

  5. 定时导出用户数据(expdp,impdp)

    一 定时导出数据: #!/bin/bash############################################################################### ...

  6. iOS 后台运行执行代码(例如定位)

  7. POJ1182 食物链---(经典种类并查集)

    题目链接:http://poj.org/problem?id=1182   食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  8. mysql root设置密码 linux

    成功方案 mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [root@localhost ~]# mysql ...

  9. python imageai 对象检测、对象识别

    imageai库里面提供了目标识别,其实也可以说是目标检测,和现在很多的收集一样就是物体识别.他可以帮你识别出各种各样生活中遇见的事物.比如猫.狗.车.马.人.电脑.收集等等. 感觉imageai有点 ...

  10. 硬币问题 tarjan缩点+DP 莫涛

    2013-09-15 20:04 题目描述 有这样一个游戏,桌面上摆了N枚硬币,分别标号1-N,每枚硬币有一个分数C[i]与一个后继硬币T[i].作为游戏参与者的你,可以购买一个名为mlj的小机器人, ...