题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009

题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字通过加或者减能组成的最多数字。

分析下三个数通过加或者减的组合以及数据规模来看,直接暴力枚举即可,枚举过程中注意不要有遗漏,最好在心里记个顺序,有条理进行枚举。

反思:当遇到数据规模不大的情况,想不出快捷方法,尝试用暴力试试。

AC代码:

#include <cstdio>
#include <set>
#include <cmath> using namespace std; int test;
int n, m;
int maxn; int solve(int a, int b, int c) {
set<int> s;
s.insert(a);
s.insert(b);
s.insert(c);
s.insert(a + b);
s.insert(a + c);
s.insert(b + c);
s.insert(abs(a - b));
s.insert(abs(a - c));
s.insert(abs(b - c));
s.insert(a + b + c);
s.insert(abs(a + b - c));
s.insert(abs(a + c - b));
s.insert(abs(b + c - a));
s.insert(abs(a - b - c));
int len = s.size();
set<int>::iterator it = s.begin();
if(*it == 0)
len--;
return len;
} int main() {
scanf("%d", &test);
while(test--) {
scanf("%d%d", &n, &m);
maxn = -1;
for(int i = 1; i <= n / 2; i++) {
int len = solve(i, n - i, m);
if(len > maxn)
maxn = len;
}
for(int j = 1; j <= m / 2; j++) {
int len = solve(j, m - j, n);
if(len > maxn)
maxn = len;
}
printf("%d\n", maxn);
}
return 0;
}

[ZOJ 3076] Break Standard Weight的更多相关文章

  1. zoj 3706 Break Standard Weight(dp)

    Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 ...

  2. [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]

    The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...

  3. zoj 3706 Break Standard Weight

    /*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块). 组合情况 i j m 三块砝码 (i+j)-m=m-(i+j) i+j i-j=j-i  i j m (i ...

  4. ZOJ 3706 Break Standard Weight 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题目意思:给出两个mass:x 和 y,问如何将其中一个 ma ...

  5. Break Standard Weight (ZOJ 3706)

    Problem The balance was the first mass measuring instrument invented. In its traditional form, it co ...

  6. HZNU Training 2 for Zhejiang Provincial Collegiate Programming Contest 2019

    赛后总结: T:今天下午参加了答辩比赛,没有给予队友很大的帮助.远程做题的时候发现队友在H上遇到了挫折,然后我就和她们说我看H吧,她们就开始做了另外两道题.今天一人一道题.最后我们在研究一道dp的时候 ...

  7. The 10th Zhejiang Provincial Collegiate Programming Contest

    Applications http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5008 string set 专场 #include& ...

  8. 2012-2014 三年浙江 acm 省赛 题目 分类

    The 9th Zhejiang Provincial Collegiate Programming Contest A    Taxi Fare    25.57% (166/649)     (水 ...

  9. ZCMU训练赛-B(dp/暴力)

    B - Break Standard Weight The balance was the first mass measuring instrument invented. In its tradi ...

随机推荐

  1. What happens when you type an URL in the browser and press enter?

    What happens when you type an URL in the browser and press enter? 1. You type maps.google.com into t ...

  2. flask(1.1)装饰器装饰多个视图函数出现的问题

    目录 1.装饰器装饰多个视图函数出现的问题 2.使用装饰器修复技术解决该问题 1.装饰器装饰多个视图函数出现的问题 代码实例: from flask import Flask, request, re ...

  3. HTML5元素周期表

    HTML5元素周期表 根元素 1. html 文档根元素 元数据和脚本 1. head HTML文档中的第一个元素.包含文档元数据 2. title 文档标题 3. meta 文档的元数据. meta ...

  4. robots.txt文件

    网站通过一个符合Robots协议的robots.txt文件来告诉搜索引擎哪些页面可以爬取.Robots.txt协议全称“网络爬虫排除标准”.一般情况下,该文件以一行或多行User-agent记录开始, ...

  5. My life

    突然想到的好笑的: 1. 世界上一共有10种人,一种是男人,另一种是女人 2. 吐槽一个网站的域名: 你这网站域名取得,跟色情网站似的 明知这是一场意外,你要不要来,明知这是一场重伤害,你会不会来: ...

  6. idea的spring整合基于xml文件配置的mybatis报Invalid bound statement (not found): com.music.dao.MusicDao.findAll的问题

    一. 题主当时就是自己尝试整合spring和mybatis的时候遇到了这个问题,当时题主只看到了用注解的方式配置的dao层,题主用的是xml文件配置的形式, 而且坑爹的是题主的两个文件的路径写的也不一 ...

  7. Linux Pycharm 添加图标到root账户桌面

    1. 去官网下载pycharm程序 2. 解压缩下载到的tar包 3. 在/usr/share/applications目录下新建一个pycharm.desktop, 写入内容如下, 注意红色字体需要 ...

  8. PHP中addslashes()和htmlspecialchars() 函数的区别及应用

    addslashes()防sql注入: 定义如下: addslashes() 函数返回在预定义字符之前添加反斜杠的字符串. 预定义字符是: 单引号(') 双引号(") 反斜杠(\) NULL ...

  9. 前端BOOM和DOOM

    BOOM :是指浏览器对象模型,它使JavaScript 有能力与浏览器进行 对话DOM:  是指文档对象模型,通过它可以访问HTML文档的所有元素 Windows对象 所有的浏览器都支持Window ...

  10. redis 命令 setbit、bitcount、getbit、bitop

    1.SETBIT key offset value 对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit). 在redis中,存储的字符串都是以二级制的进行存在的. 举例: 设置一个 ke ...