/*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块)。 
组合情况 i j m 三块砝码
(i+j)-m=m-(i+j) i+j i-j=j-i  i j m
(i+m)-j=j-(i+m) i+m i-m=m-i   i+j+m
(j+m)-i=i-(j+m) j+m j-m=m-j
*/
#include<string.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int he[];/*砝码组合质量之和作为序号,来判断改质量是否已经访问过(防止有相同的质量再次使用)*/
int solove(int n,int m);
int main(int argc, char* argv[])
{
int t,n,m,h,max; scanf("%d",&t);
while(t--)
{ scanf("%d%d",&n,&m); max=solove(n,m);/*当分n的时候,得到最大情况数量*/
h=solove(m,n);/*当分m的时候,得到最大情况数量*/
if(max<h)
max=h;
printf("%d\n",max); }
return ;
}
int solove(int n,int m)
{
int i,j,max,count,t;
max=count=;
for(i=;i<=(n+)/;i++)/*因为1-n最后会有一半左右重复*/
{
memset(he,,sizeof(he));/*每一次砝码新的分法,这个数组需重新初始化*/
count=;
j=n-i; t=i+j+m;
if(he[t]==)
{he[t]=;count++;}/*如果这个质量没有访问过组合数就加1,然后设置访问过*/ t=abs(i+j-m);
if(he[t]==)
{he[t]=;count++;} t=abs(j+m-i);
if(he[t]==)
{he[t]=;count++;} t=abs(m+i-j);
if(he[t]==)
{he[t]=;count++;} t=i+m;
if(he[t]==)
{he[t]=;count++;} t=i+j;
if(he[t]==)
{he[t]=;count++;} t=j+m;
if(he[t]==)
{he[t]=;count++;} t=abs(i-j);
if(he[t]==)
{he[t]=;count++;} t=abs(i-m);
if(he[t]==)
{he[t]=;count++;} t=abs(j-m);
if(he[t]==)
{he[t]=;count++;} t=i;
if(he[t]==)
{he[t]=;count++;} t=j;
if(he[t]==)
{he[t]=;count++;} t=m;
if(he[t]==)
{he[t]=;count++;} if(he[]==)/*如果有组合的结果是0,就不算在内*/
count--; if(max<count)
max=count;
}
return max;
}

zoj 3706 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 解题报告

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

  4. [ZOJ 3076] Break Standard Weight

    题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...

  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. DMVsinSQLServer -- 备

    /*************************************************************************************************** ...

  2. [LeetCode][Python]Reverse Integer

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/reverse ...

  3. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(七)

    目标: 1. 完成最终的设备驱动,增加具体的watchdog设备操作的代码. 测试代码: 代码最终实现见cwd_demo.c 代码只实现了read与write.  没有实现ioctl. 因此,我们可以 ...

  4. 2014 Web开发趋势

    本文翻译自:http://www.pixelstech.net/article/1401629232-Web-design-trends-for-2014 如今,已然到了Web横行的时代.越来越多的资 ...

  5. NGINX 多个域名配置

    多个域名配置: 依赖于 include  这个功能会加在 这2个文件夹下的所有配置文件. 所以我们可以配置多个   conf  放置于这些文件夹中.这样就是先了多个域名配置 conf 内容大致如下 s ...

  6. EJBCA认证系统结构及相关介绍

    写作此文的主要目的是记录下EJBCA认证系统的系统结构及相关部件作用的介绍,方便后面查阅使用.

  7. SSLSocket实现服务端和客户端双向认证的例子

    首先创建服务器端私有密钥和公共密钥1, keytool -genkey -alias serverkey -keystore kserver.ks    密码: serverpass2, keytoo ...

  8. iis 目录枚举文件枚举解决方案

    1.关闭windows的8.3格式功能. 修改注册表键值: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem 修改NtfsD ...

  9. STL模板_multimap_智能指针作为键值

    map的键值的类型 -可以是自定的类型(对象.函数指针.智能指针....) -但是有副作用-当自己定义的类型键值无法用系统自己提供的 < 或者 > 进行排序的时候,会出现各种问题 -所以需 ...

  10. 百度editor调用【图片上传阿里云】

    百度editor调用简单,但是图片和文件上传阿里云就有点难度了.下面我详细说一下. 百度富文本编辑器下载地址:http://ueditor.baidu.com/website/download.htm ...