[ACM_水题] ZOJ 3706 [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 1, 4, 5 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 ≤ x, y ≤ 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 砝码拆分,可称质量种类,暴力]的更多相关文章
- zoj 3706 Break Standard Weight(dp)
Break Standard Weight Time Limit: 2 Seconds Memory Limit: 65536 ...
- zoj 3706 Break Standard Weight
/*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块). 组合情况 i j m 三块砝码 (i+j)-m=m-(i+j) i+j i-j=j-i i j m (i ...
- ZOJ 3706 Break Standard Weight 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题目意思:给出两个mass:x 和 y,问如何将其中一个 ma ...
- [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 ...
- [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]
MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...
- [ZOJ 3076] Break Standard Weight
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...
- ACM_水题你要信了(修改版)
水题你要信了 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某发最近又认识了很多妹(han)子,可是妹(han)子一多不免有时会 ...
- Break Standard Weight (ZOJ 3706)
Problem The balance was the first mass measuring instrument invented. In its traditional form, it co ...
- 水题 ZOJ 3875 Lunch Time
题目传送门 /* 水题:找排序找中间的价格,若有两个,选价格大的: 写的是有点搓:) */ #include <cstdio> #include <iostream> #inc ...
随机推荐
- JDK 环境变量设置
.net转JAVA了.记心不好,记录一下. 安装好jdk(64位)后找到我的电脑(右键)>属性>高级选项卡>环境变量>,里面有管理员的用户变量,有系统变量.我选的是系统变量.点 ...
- GBDT(MART) 迭代决策树入门教程 | 简介
GBDT(MART) 迭代决策树入门教程 | 简介 http://blog.csdn.net/w28971023/article/details/8240756
- css属性word-spacing和letter-spacing的区别
word-spacing和letter-spacing用来定义单词或者字母之间的水平空白间隔.顾名思义,word-spacing定义了单词之间的空白,例如: <div style="w ...
- [2015hdu多校联赛补题]hdu5372 Segment Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5372 题意:进行n次操作,操作分两种,0和1,每一个0操作按出现顺序有一个编号(从1开始 0操作 0 ...
- Python—元组tuple
列表的知识其实就类似于c语言中的数组,可插入.修改.list=[a,b,c,d] 而元组tuple,一旦初始化即不可修改.好处与绝对安全. 定义一个空的元组:t=() 定义只有一个元素的元组:t=(1 ...
- deep learning
今天跑一个模型,程序都没变,就配置文件变了.但是总是很快就显示loss为nan. 检查配置文件还是不行,把其中loss改为0还是不行.最后搁置了一下,再回头对比一下电脑上的和服务器上的,发现一个配置文 ...
- ORACLE服务端详细安装步骤(配图解)
ORACLE服务端的安装及配置 l 将下载的安装包解压缩,双击[setup.exe]文件,系统检查监听参数,耐心等待,完成后出现如下界面,电子邮件可不填,"我希望..."建议不勾选 ...
- mysql 循环插入日期递增
create procedure wk() begin declare i int; ; do insert into t (myday) values (date_sub(curdate(),int ...
- 柬埔寨手机上网资费套餐(3G/4G上网)
柬埔寨三大运营商 Cellcard 官网套餐详情http://www.cellcard.com.kh/cellcard-internet Metfone 官网套餐详情http://www.met ...
- Web大规模高并发请求和抢购的解决方案
电商的秒杀和抢购,对我们来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验.当一个Web系统,在一秒钟内收到数以万计甚至更多请求时,系统的优化和稳定至关重要.这次我们 ...