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. myeclipse中Web App Libraries无法自动识别lib下的jar包

    在项目目录下找到.object文件修改 <natures> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature ...

  2. NGUI Draw Calls优化(思路)

    用NGUI做界面的时候发现不注意GameObject(或者说Widget)的depth的话,单独运行界面时,Draw Calls挺高的: 网上搜了一下,大把的博客说的都是类似以下的原则: (PS:以下 ...

  3. 技术英文单词贴--W

    W widget 小工具,小部件

  4. nginx解析php请求为404

    刚搭建了lnmp环境,发现如果讲我的程序放在某个文件夹的时候,然后nginx进行代理的时候竟然会是404: nginx配置如下: # pass the PHP scripts to FastCGI s ...

  5. android studio 代理配置

    android studio 代理设置,只支持http代理,不能用ss服务 中间加一层http转换 1远端ss 2client ss 端口 A 3client privoxy服服 代理ss A端口 到 ...

  6. php 图片处理类

    <?php /** * 图片类 * @author <420012223@qq.cn> */ class Image { public $uploadImagePath = './t ...

  7. 問題排查:行動裝置網頁前端 UI 設計 (2)

    之前上網找了個星級評分的範例來玩, 當然這個範例已經用在另一個專案了, 目前看起來沒什麼狀況, 不過在移植到目前的專案之後, 就出現了怪現象: 1. 在大部份時間裡,點擊星星不會有任何反應 2. 即便 ...

  8. coreseek实战(一):windows下coreseek的安装与测试

    coreseek实战(一):windows下coreseek的安装与测试 网上关于 coreseek 在 windows 下安装与使用的教程有很多,官方也有详细的教程,这里我也只是按着官方提供的教程详 ...

  9. 让图片在div 中居中的方法

    方法一: 思路:利用text-align属性将图片水平居中,然后设置padding-top的值使其垂直居中. 结构如下: <div> <img src="images/tt ...

  10. python学习之路-day2-pyth基础2

    一.        模块初识 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,第三方库存放位置:site-packages sys模块简介 导入模块 import sys 3 sys模 ...