[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 ...
随机推荐
- eclipse中导入项目后中文成乱码解决办法
转自:http://blog.163.com/lang_zi_ming/blog/static/1140161762010412112650774/ 编程时在往eclipse中导入项目后 项目中的中文 ...
- css 中 list-style-image:
用于设置<a>标签的默认格式的背景图片
- Lua metatable & metamethod
[Lua metatable & metamethod] Lua中的每个值都有一套预定义的操作集合,比如数字是可以相加的,字符串是可以连接的,但是对于两个table类型,则不能直接进行“+”操 ...
- 问题: ActivityManager: Warning: Activity not started, its current task has been brought to the front
运行程序时看控制台有这样的错误,应用程序没跑起来. 解决办法:project-->Clean
- nvidia 各种卡
cudnn是针对maxwell优化的啊, maxwell下的各种卡都是游戏卡,具体可以见: https://developer.nvidia.com/maxwell-compute-architect ...
- pause 和 title
-------siwuxie095 pause 暂停批处理程序,并显示:请按任意键继续- 暂停高级技巧: pause>nul 只暂停,不显示任何信息,且光标移到下一行 如果不想用默认提示语:请按 ...
- Spark 机器学习
将Mahout on Spark 中的机器学习算法和MLlib中支持的算法统计如下: 主要针对MLlib进行总结 分类与回归 分类和回归是监督式学习; 监督式学习是指使用有标签的数据(LabeledP ...
- Android--多线程之Handler(转)
前言 Android的消息传递机制是另外一种形式的“事件处理”,这种机制主要是为了解决Android应用中多线程的问题,在Android中不 允许Activity新启动的线程访问该Activity里的 ...
- jQuery实现无缝滚动条
很多时候只看别人的代码时很难看懂.有很多原因,有时候可能是没有耐心,这时候看一下实现的原理就很快明白代码的内容,所以要加些注释,让自己让别人都能看明白:有的时候就是因为知识有限就是不懂,哪怕代码很简单 ...
- java生成base64编码的png
java代码: 引用包: import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java. ...