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 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...
随机推荐
- hdu 4333 扩展kmp+kmp重复字串去重
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...
- Ubuntu 14.04 用户如何安装深度音乐播放器和百度音乐插件
播放本地音乐或者收听国外的音乐电台,Ubuntu 14.04 自带的音乐播放器 Rhythmbox 完全能够满足,但是如果你想有像酷狗那样的国内播放器就需要折腾一下,还好有深度音乐播放器,这是一款完全 ...
- 史上最简单Git入门教程
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 工作原理 / 流程: Workspace:工作区Index / Stage:暂存区Repository:仓库区(或本地仓库)Remo ...
- AngularJS入门教程之数据绑定原理详解
这篇文章主要是写给新手的,是给那些刚刚开始接触Angular,并且想了解数据帮定是如何工作的人.如果你已经对Angular比较了解了,那强烈建议你直接去阅读源代码. Angular用户都想知道数据绑定 ...
- Oracle中select 1和select *的区别
转自:https://www.linuxidc.com/Linux/2010-05/26202.htm 创建myt表并插入数据,如下: create table myt(name varchar2,c ...
- [转]Spring Security Oauth2 认证流程
1.本文介绍的认证流程范围 本文主要对从用户发起获取token的请求(/oauth/token),到请求结束返回token中间经过的几个关键点进行说明. 2.认证会用到的相关请求 注:所有请求均为po ...
- 借助Spring工具类如何实现支持数据嵌套的赋值操作
假设有两个Bean A和B,想将B中的属性赋值到A实体中,可以使用get set来实现,当属性过多时,就会显得很冗余,可以使用spring提供的BeanUtils.copyProperties()来实 ...
- 用一个N点复序列的FFT同时计算两个N点实序列离散傅里叶变换
一.功能 用一个\(N\)点复序列快速傅立叶变换算法来同时计算两个\(N\)点实序列的离散傅立叶变换. 二.方法简介 假设\(x(n)\)与\(y(n)\)都是长度为\(N\)的实序列,为计算其离散傅 ...
- man 手册--nc
man 手册--nc NCAT(1) Ncat Reference Guide NCAT(1) NAME ncat - Concatenate and redirect sockets SYNOPSI ...
- RAM disk
Linux 系统创建RAM disk 参考: https://blog.csdn.net/linuxdashencom/article/details/52319671 https://www.lin ...