Break Standard Weight (ZOJ 3706)
Problem
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 xand 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
题解:直接枚举暴力所有情况,比较那种拆法多就可以了。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int a[520], vis[505] = {0};
int f(int a, int b, int c)
{
memset(vis, 0, sizeof(vis));
int x = a;
int ans = 0;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + b + c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a + b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a + b -c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = -a - b +c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b - a;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c + b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c - b;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = b - c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a + c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = a - c;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
x = c - a;
if(x > 0 && vis[x] == 0){vis[x] = 1;ans++;}
return ans;
}
int main()
{
int t,i,n,ans,m,j, xx = 0;
while(scanf("%d", &t) != EOF)
{
while(t--)
{
xx = 0;
scanf("%d %d", &n, &m);
for(i = 1; i <= n/2; i++)
{
ans = f(i, n - i, m);
xx = max(ans, xx);
}
for(i = 1; i <= m/2; i++)
{
ans = f(i, m - i, n);
xx = max(ans, xx);
}
printf("%d\n", xx);
}
}
return 0;
}
Break Standard Weight (ZOJ 3706)的更多相关文章
- zoj 3706 Break Standard Weight(dp)
Break Standard Weight Time Limit: 2 Seconds Memory Limit: 65536 ...
- 【PAT】1053 Path of Equal Weight(30 分)
1053 Path of Equal Weight(30 分) Given a non-empty tree with root R, and with weight Wi assigned t ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]
The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...
- 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy
Information Entropy Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Information ...
- 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 ...
- [ZOJ 3076] Break Standard Weight
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...
随机推荐
- [Vue]vue-loader作用
一.vue文件 vue文件是一个自定义的文件类型,用类HTML语法描述一个vue组件,每个.vue组件包含三种类型的顶级语言快< template>< script>< ...
- C++虚函数【Java有虚函数吗?】
1,简单介绍 定义在基类中的函数,子类必须对其进行覆写![必须对其进行覆写?!]——Java中的接口.Abstract方法中的抽象类也有这样的要求. C++中定义: virtual void deal ...
- JSP开发 路径问题汇总
//第一种 jsp 表达式 <%=request.getContextPath %> 获取到 web项目名的绝对路径 <!--使用绝对路径的方式引入CSS文件--> <l ...
- 前端关于 superSlide.js 使用,一款基于jquery的前端控件
1引用jQuery.js 和 jquery.SuperSlide.js 2 编写HTML ** 以下是默认的HTMl结构,分别是 ".hd" 里面包含ul, ".bd&q ...
- spingboot启动报驱动Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of th
原因: springboot应用了最新的驱动com.mysql.cj.jdbc.Driver,这个驱动需要用mysql-connector-java包的6.x版本才可以, 而mysql-connect ...
- JS数组操作,赋值指向同一指针
1.使用slice() 可使用slice()进行复制,因为slice()返回也是数组. var array1 = new Array("1","2"," ...
- 串口工具kermit(ubuntu)
安装 # sudo apt-get install ckermit 配置 kermit启动时,会首先查找~/.kermrc,然后再遍历/etc/kermit/kermrc # vi /etc/kerm ...
- 结对编程作业(python实现)
一.Github项目地址:https://github.com/asswecanfat/git_place/tree/master/oper_make 二.PSP2.1表格: PSP2.1 Perso ...
- js 实现复制功能的四种方式的优劣对比
今日网上浏览别人项目,看到有人用了document.execCommand这个属性,于是想起之前我选用Clipboard.js 来实现.对于这种不常用的属性还是不太放心,于是随手查了下关于复制的资料, ...
- python中yield的用法详解-转载
原文链接:https://blog.csdn.net/mieleizhi0522/article/details/82142856 ,今天在写python爬虫的时候,循环的时候用到了yield,于是搜 ...