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. uncompyle6安装使用方法

    uncompyle6是一个原生python的跨版本反编译器和fragment反编译器,是decompyle.uncompyle.uncompyle2等的接替者. uncompyle6可将python字 ...

  2. AtCoder Grand Contest 040 B - Two Contests

    传送门 一看就感觉很贪心 考虑左端点最右的区间 $p$ 和右端点最左的区间 $q$ 如果 $p,q$ 属于同一个集合(设为 $S$,另一个集合设为 $T$),那么其他的区间不管是不是在 $S$ 都不会 ...

  3. 十大经典排序【Java实现,手工作坊式】

    终于把排序这个硬骨头,但是又很基础的知识点,自己手撕了一遍!之前,使用Python看着算法导论的书手撕过一遍,印象不是很深刻,容易忘记!好记性不如烂笔头!多自己思考解决问题 1,交换类CAS[最简单] ...

  4. 奇妙的算法【7】-贪婪算法-dp

    问题1描述:[贪婪算法,Dijistra算法] ①有一只兔子要从一个N*N的二维矩阵方格中从上跳到下面: ②每次只能向左或向下,越过一个方格,跳到下一个方格中: ③被越过的方格中的数值,表示该兔子越过 ...

  5. 帝国cms“建立目录不成功,请检查目录权限”的解决方法

    就这个看似简单的问题我折腾了两天,百度看产生这个问题的原因有很多也很宽泛,大部分说的是初始化内置数据,但我出现“建立目录不成功,请检查目录权限”的原因估计只有少部分人会遇到. 内置初始化数据是你上传文 ...

  6. 编译openwrt backfire过程中出现的问题

    参考的步骤如链接: http://www.right.com.cn/forum/forum.php?mod=viewthread&tid=124604 在make menuconfig的时候出 ...

  7. 基于【 centos7】二 || 系统时间与网络时间同步

    # date // 查看系统时间 #hwclock // 查看硬件时间 # yum -y install ntp ntpdate 安装ntpdate工具 # ntpdate cn.pool.ntp.o ...

  8. python打印表格式数据-星号或注释

    python打印表格式数据,留出正确的空格,格式化打出 代码如下: def printPicnic(itemsDict,leftWidth,rightWidth): print('PICNIC ITE ...

  9. \lib\cmsis\stm32f10x.h(298): error: #67: expected a "}"

    首先介绍一下csdn屏蔽广告 这个至关重要,请参考 https://blog.csdn.net/qq_40881680/article/details/82226562 更新KEIL5以后,原KEIL ...

  10. 【大数据】Clickhouse基础知识

    第1章 ClickHouse概述 1.1 什么是ClickHouse ClickHouse 是俄罗斯的Yandex于2016年开源的列式存储数据库(DBMS),主要用于在线分析处理查询(OLAP),能 ...