Problem

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 6 exactly.

In the beginning of this problem, there are 2 standard weights, which masses are xand 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 13 special 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 integers x 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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int a[520], vis[505] = {0};
int f(int a, int b, int c)
{
memset(vis, 0, sizeof(vis));
int x = a;
int ans = 0; if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + b + c; if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a + b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a + b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a - b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;} x = a + b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b - a;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;} x = c + b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c - b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b - c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;} x = a + c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c - a;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
return ans; }
int main()
{
int t,i,n,ans,m,j, xx = 0;
while(scanf("%d", &t) != EOF)
{
while(t--)
{
xx = 0;
scanf("%d %d", &n, &m);
for(i = 1; i <= n/2; i++)
{
ans = f(i, n - i, m);
xx = max(ans, xx);
}
for(i = 1; i <= m/2; i++)
{
ans = f(i, m - i, n);
xx = max(ans, xx);
}
printf("%d\n", xx);
}
}
return 0;
}

Break Standard Weight (ZOJ 3706)的更多相关文章

  1. zoj 3706 Break Standard Weight(dp)

    Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 ...

  2. 【PAT】1053 Path of Equal Weight(30 分)

    1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight W​i​​ assigned t ...

  3. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  4. [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]

    The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...

  5. 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...

  6. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information ...

  7. zoj 3706 Break Standard Weight

    /*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块). 组合情况 i j m 三块砝码 (i+j)-m=m-(i+j) i+j i-j=j-i  i j m (i ...

  8. ZOJ 3706 Break Standard Weight 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题目意思:给出两个mass:x 和 y,问如何将其中一个 ma ...

  9. [ZOJ 3076] Break Standard Weight

    题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...

随机推荐

  1. 区间第k大问题 权值线段树 hdu 5249

    先说下权值线段树的概念吧 权值平均树 就是指区间维护值为这个区间内点出现次数和的线段树 用这个加权线段树 解决第k大问题就很方便了 int query(int l,int r,int rt,int k ...

  2. krpano 全景学习

    krpano 切片工具下载 https://krpano.com/tools/ krpano 案例使用 https://krpano.com/examples/usage/#top krpano  是 ...

  3. Form key length limit 2048 exceeded ,提交数据时,数据的键过长 或者是上传文件过大

    在ASP.NET Core MVC中,文件的key 默认最大为2048,文件上传的最大上传文件默认为20MB,如果我们想上传一些比较大的文件,就不知道怎么去设置了,没有了Web.Config我们应该如 ...

  4. mysql 添加省市编码表

    省表格: --省级 Provincial create table Provincial(pid int,Provincial varchar(50),primary key (pid)) inser ...

  5. datagrid行内编辑

    编辑属性 :editor: { type: 'text'} $('#listShow').datagrid({ height : 478, pagesize : 20, pageList : [20, ...

  6. jQuery异步请求ajax()之complete参数详解

    请求完成后回调函数 (请求success 和 error之后均调用).这个回调函数得到2个参数:XMLHTTPRequest) 对象和一个描述请求状态的字符串("success", ...

  7. background 背景图片 --css3

    background 1.设置背景平铺background-repeat round :图片会进行缩放后平铺space : 图片会进行平铺,中间留下空白空间 注:当滚动行为设为fixed,round和 ...

  8. JavaScript知识点:分支结构(if、switch)+算法例题

    if-else分支 1.if条件应该是boolean类型的值或表达式 2.如果条件不是Boolean,会进行自动转换 以下几种情况会默认转换为 false: if(0).if(0.0) if(NaN) ...

  9. 解决wpscan无法更新

    如果wpscan无法更新的话 一般的原因都是源或者更新地址无法访问 下面解决 updatedb #先更新一下系统的索引 locate wpscan #定位到wpscan的目录 大概就是updater. ...

  10. flex布局下img图片变形的解决方法

      图片正常效果   图片变形效果 一.flex-shrink: 0 给 img 设置 flex-shrink: 0; flex-shrink 的默认值为1,如果没有显示定义该属性,将会自动按照默认值 ...