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 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 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

Author: YU, Zhi
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

题目大意:给你2个砝码X,Y,你可以把一个打破变成2个砝码,用新的3个砝码可以称出最多质量的种类是多少?

解题思路:暴力枚举所有的打破砝码的方法,然后针对每种情况计算出所有可能的组合放进map里[可以去除重复的数字],则map的大小就是该种拆法可以称出的种类数。[这里要注意0不算]

 #include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int x,y;
cin>>x>>y;
set<int>Q;
Q.clear();
int max=;
for(int i=;i<=x/;i++){
int a=i,b=x-i,c=y;
Q.insert(a);//单独一个砝码
Q.insert(b);
Q.insert(c);
Q.insert(a+b);//2个砝码
if(a-b!=)Q.insert(abs(a-b));
Q.insert(a+c);
if(a-c!=)Q.insert(abs(a-c));
Q.insert(b+c);
if(b-c!=)Q.insert(abs(b-c));
Q.insert(a+b+c);//3个砝码
if(a+b-c!=)Q.insert(abs(a+b-c));
if(a-b+c!=)Q.insert(abs(a-b+c));
if(a-b-c!=)Q.insert(abs(a-b-c));
//cout<<a<<' '<<b<<' '<<c<<' '<<Q.size()<<'\n';
if(Q.size()>max)max=Q.size();
Q.clear();
}//拆x
for(int i=;i<=y/;i++){
int a=i,b=y-i,c=x;
Q.insert(a);
Q.insert(b);
Q.insert(c);
Q.insert(a+b);
if(a-b!=)Q.insert(abs(a-b));
Q.insert(a+c);
if(a-c!=)Q.insert(abs(a-c));
Q.insert(b+c);
if(b-c!=)Q.insert(abs(b-c));
Q.insert(a+b+c);
if(a+b-c!=)Q.insert(abs(a+b-c));
if(a-b+c!=)Q.insert(abs(a-b+c));
if(a-b-c!=)Q.insert(abs(a-b-c));
//cout<<a<<' '<<b<<' '<<c<<' '<<Q.size()<<'\n';
if(Q.size()>max)max=Q.size();
Q.clear();
}//拆y
cout<<max<<'\n';
}return ; }

[ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]的更多相关文章

  1. zoj 3706 Break Standard Weight(dp)

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

  2. zoj 3706 Break Standard Weight

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

  3. ZOJ 3706 Break Standard Weight 解题报告

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

  4. [ACM_水题] ZOJ 3714 [Java Beans 环中连续m个数最大值]

    There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...

  5. [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]

    MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...

  6. [ZOJ 3076] Break Standard Weight

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

  7. ACM_水题你要信了(修改版)

    水题你要信了 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某发最近又认识了很多妹(han)子,可是妹(han)子一多不免有时会 ...

  8. Break Standard Weight (ZOJ 3706)

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

  9. 水题 ZOJ 3875 Lunch Time

    题目传送门 /* 水题:找排序找中间的价格,若有两个,选价格大的: 写的是有点搓:) */ #include <cstdio> #include <iostream> #inc ...

随机推荐

  1. jquery validate ajax submit form

    when the jquery validation plugin is used for validating the form data, such as below: html code: &l ...

  2. 《深入理解Nginx》阅读与实践(一):Nginx安装配置与HelloWorld

    最近在读陶辉的<深入理解Nginx:模块开发与架构解析>,一是想跟着大牛练练阅读和编写开源代码的能力,二是想学学Nginx优秀的架构设计,三是想找一个点深入下Linux下网络编程的细节.侯 ...

  3. EF联合查询的新用法

    用EF很多年了,做联合查询时,只知道linq和lambda两种语法,今天朋友发了一个链接,打开看后发现是EF内置的新的关于联合查询的方法,赶紧抄录下来,以备后用. 现在先把这几种方法,各写一个例子,便 ...

  4. iOS定位到崩溃代码行数

    不知道大家是不是在代码调试过程中经常遇到项目崩溃的情况: 比如: 数组越界: 没有实现方法选择器: 野指针: 还有很多很多情况.......昨天学到了一种可以直接定位到崩溃代码行数的一个命令,记录一下 ...

  5. 根据IP获取省市 .

    public class IPAddress { /// <summary> /// 得到真实IP以及所在地详细信息(Porschev) /// </summary> /// ...

  6. 使用 IntraWeb (38) - TIWAppForm、TIWForm、TIWBaseHTMLForm、TIWBaseForm

    窗体 TIWAppForm 所在单元及继承链: IWAppForm.TIWAppForm 主要成员: property OnURLRequest: TOnURLRequest //响应下面的 DoUR ...

  7. php插入排序

    //php版插入排序 $arr=array('','5','3','7','6','4','8','2');     for($i=2;$i<count($arr);$i++)     {   ...

  8. GATK使用说明-GRCh38(Genome Reference Consortium)(二)

    Reference Genome Components 1. GRCh38 is special because it has alternate contigs that represent pop ...

  9. 【.net】关于RegexOptions中的各个枚举值的含义

      Member name Description   Compiled Specifies that the regular expression is compiled to an assembl ...

  10. uploadify 上传遇到跨域问题

    flash上传跨域,一般是加入crossdomain.xml 我用了别人的图片服务器,只能做此下策: //CURLFile 实现 $file = $_FILES['Filedata']['tmp_na ...