/*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块)。 
组合情况 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. Android XListView实现原理讲解及分析

    XListview是一个非常受欢迎的下拉刷新控件,但是已经停止维护了.之前写过一篇XListview的使用介绍,用起来非常简单,这两天放假无聊,研究了下XListview的实现原理,学到了很多,今天分 ...

  2. Android学习笔记:利用httpclient和AsyncTask 发起网络http post操作

    1.在android4中,发起网络http操作,不能在Activity的事件(即主线程)中进行,必须在单独的线程中操作. 另外进行网络操作,需要在manifest文件中增加如下的权限: <use ...

  3. JavaEE Tutorials (19) - Web应用安全入门

    19.1Web应用安全概述29519.2保护Web应用安全296 19.2.1指定安全约束297 19.2.2指定认证机制300 19.2.3在部署描述文件中指定认证机制302 19.2.4声明安全角 ...

  4. linux内核参数调优,缓冲区调整,tcp/udp连接管理,保持,释放优化,gossary,terms

    changing a readonly file (linu single user mode)

  5. 自定义标签体、MVC

    自定义标签 文件以tld结尾,放在webinfo中 标签名 引用类 标签体 继承SimpleTagSupport,复写doTag() getContext(); getjspBody()   invo ...

  6. Baskets of Gold Coins

    Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu-4468-Spy-KMP+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4468 题目意思: 给你一个串r,求一个串s,使得s的前缀1+s的前缀2+s的前缀3+...+s的前缀 ...

  8. asp.net 向后台提交 html 代码段 包括 <> 标签

    首先 在默认情况向标签类的东西是不会让你提交的 这是出于.net 的默认安全机制 我们要先在 <%@ page %> 里边加上  ValidateRequest="false&q ...

  9. JS把字符串转换为数字的方法

     方法: (1)Number(),强制类型转换,接受一个参数. (2)parseInt(),把字符串转换为整形数字,可以接受一个或两个参数,其中第二个参数代表转换的基数,能够正确的将二进制.八进制.十 ...

  10. SQL学习之分组数据Group by

    简介:"Group By"根据字面上的意思理解,就是根据"By"后面指定的规则对数据进行分组(分组就是将一个数据集按照"By"指定的规则分成 ...