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 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...
随机推荐
- Bitbucket入门手册
老大要我去调研一下有什么好用的免费软件版本管理工具,有利于小团队开发的.我第一个想到的就是git,经常在git下东西,听说它的代码仓库好用,于是就注册了一个github的账号,创建仓库的时候才发现只能 ...
- Junit 学习笔记
目录 Junit 学习笔记 1. 编写测试用例时需要注意 2. 出现结果分析 3. Junit 运行流程 4. Junit 常用注解 5. Junit 测试套件的使用 6. Junit 参数化设置 J ...
- maven项目打包和编译跳过单元测试和javadoc
代码中可能由于单元测试.注释(方法中的参数)或者maven javadoc插件的问题导致无法打包,影响工作,为避免这两种情况可以在打包时输入命令: mvn clean install -Dmaven. ...
- 使用ctypes调用系统C API函数需要注意的问题,函数参数中有指针或结构体的情况下最好不要修改argtypes
有人向我反应,在代码里同时用我的python模块uiautomation和其它另一个模块后,脚本运行时会报错,但单独使用任意一个模块时都是正常的,没有错误.issue链接 我用一个例子来演示下这个问题 ...
- 前端html转pdf
转 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...
- leetcode-88. 合并两个有序数组 · Aaray
题面 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 样例 1. 输入: nums1 = [1,2,3,0,0,0], m ...
- YII2 实现dropDownList 联动事件
一.视图中 <div class="main-form"> <?php $form = ActiveForm::begin(); ?> <?= $fo ...
- 【python+ddt】DDT模块的使用
ddt模块包含了一个类的装饰器ddt和两个方法的装饰器: data:包含多个你想要传给测试用例的参数: file_data:会从json或yaml中加载数据: unpanck:通常data中包含的每一 ...
- zabbix监控MySQL,Tomcat及配置邮件报警
目录 一.思路 二.部署.配置 环境 安装zabbix 对zabbix进行初步优化 添加监控主机 部署监控Tomcat 配置邮件报警 三.总结 一.思路 首先搭建zabbixserver,本机需要安装 ...
- IntelliJ IDEA详细配置和使用教程(适用于Java开发人员)
关闭Intellij IDEA自动更新在File->Settings->Appearance & Behavior->System Settings->Updates下 ...