[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 ...
随机推荐
- avalon2学习教程15指令总结
avalon的指令在上一节已经全部介绍完毕,当然有的语焉不详,如ms-js.本节主要总结我对这方面的思考与探索. MVVM的成功很大一语分是来自于其指令,或叫绑定.让操作视图的功能交由形形式式的指令来 ...
- rtsp 协议 详细讲解
转载自:http://www.mikewootc.com/wiki/net/protocol/rtsp.html 目录: 概述 RTSP简介 协议特点 协议细节 典型的rtsp交互过程 RTSP消息格 ...
- VC++ 将资源位图画到窗口上去的方法
第一种方法最简单:直接看代码 CImage img; img.LoadFromResource(AfxGetInstanceHandle(), IDB_BITMAP1); img.Draw(*pDc, ...
- VC++ WINDOWS自定义消息范围
WINDOWS自定义消息WM_USER和WM_APP WM_USER常量是Windows帮助应用程序定义私有窗口类里的私有消息,通常使用WM_USER+一个整数值,但总值不能超过0x7FFF(十进制: ...
- 上传文件(单文件)(FormData)(前端代码+.NET服务器端)
由于样式需要不能直接用file,只能用文本框+按钮 <form class="form-horizontal form-bordered form-row-strippe" ...
- Android消息推送——JPush极光推送
刚看了一篇关于Android消息推送评测总结的博客http://www.cnblogs.com/logan/p/4514635.html: 自己也对原学过的JPush极光进行一下小结,方便后续工作使用 ...
- maven中添加servlet、jsp依赖
或者在eclipse中,右键项目名称->Maven->Add Dependency->输入servlet,会自动找到最新的版本(记得联网哦),如图:
- mysql学习(二)
(1)存储过程:存储过程是SQL语句和控制语句的预编译集合,以一个名称存储并作为一个单元处理: (2)存储过程优点:增强SQL语句的功能和灵活性,实现较快的执行速度,减少网络流量: (3)存储过程结构 ...
- 《CSS3秘籍》(第三版)-读书笔记
第3章 选择器:明确设置哪些样式 每个样式(或者规则)由两个主要部分组成:选择器是告诉浏览器要格式化什么内容:声明块则列出浏览器用来给选择器定义样式的格式化指令. 1.标签选择器:整体控制 标签选择器 ...
- ios NSThred多线程简单使用
关于NSThred开启多线程的方法 - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg [self perfor ...