zoj 3706 Break Standard Weight
- /*题意:将两个砝码中的其中一个分成两块,三块组合最多有几种情况(可以只有一块,或者两块)。
组合情况 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的更多相关文章
- zoj 3706 Break Standard Weight(dp)
Break Standard Weight Time Limit: 2 Seconds Memory Limit: 65536 ...
- [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]
The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...
- 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 题意:给你两个数字,可以把其中一个拆成两个数字,计算这三个数字 ...
- Break Standard Weight (ZOJ 3706)
Problem The balance was the first mass measuring instrument invented. In its traditional form, it co ...
- HZNU Training 2 for Zhejiang Provincial Collegiate Programming Contest 2019
赛后总结: T:今天下午参加了答辩比赛,没有给予队友很大的帮助.远程做题的时候发现队友在H上遇到了挫折,然后我就和她们说我看H吧,她们就开始做了另外两道题.今天一人一道题.最后我们在研究一道dp的时候 ...
- The 10th Zhejiang Provincial Collegiate Programming Contest
Applications http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5008 string set 专场 #include& ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- ZCMU训练赛-B(dp/暴力)
B - Break Standard Weight The balance was the first mass measuring instrument invented. In its tradi ...
随机推荐
- 转:onkeypress、onkeydown、onkeyup 区别
在使用JavaScript做WEB键盘事件侦听捕获时,主要采用onkeypress.onkeydown.onkeyup三个事件进行出来.该三个事件的执行顺序如下:onkeydown -> onk ...
- poj1547---结构数组
题意:老师发给每个学生的橡皮泥相同,找出谁抢了谁的橡皮泥 思路:结构数组存储每个学生的橡皮总量,和名字 /* 结构数组存储用户信息--只放名称和体积 while输入循环复用长宽高变量 for循环求所有 ...
- openNebulafrontEnd ComputeNode 配置记录
1,OpenNebula nfs(file system shared) for image datastore;
- S3C6410嵌入式应用平台构建(二)
[2014-4/11~4/14]经过之前的实验,对Uboot已经有了大体的了解,前我们已经把led灯给点亮,但这不是我们的根本目的,我们是要进入boot启动,经过两天的分析代码和反复的实验,终于可以进 ...
- C#中var关键字【转】
[转]http://blog.csdn.net/courageously/article/details/5695626 var关键字是C# 3.0开始新增的特性,称为推断类型 . 可以赋予局部变量推 ...
- CAD二次开发(.NET)之PaletteSet和Palette
在CAD中经常用到停靠或浮动的PaletteSet,比如:特性.图层特性管理器.工具选项板等(以下截图来自AutoCAD2010界面). 特性PaletteSet(停靠) 图层特性管理器Palette ...
- Android基础-EditText键盘的显示与隐藏
场景一.点击EditText之外的空白区域隐藏键盘: how to hide soft keyboard on android after clicking outside EditText? 首先定 ...
- java 乱码详解_jsp中pageEncoding、charset=UTF -8"、request.setCharacterEncoding("UTF-8")
http://blog.csdn.net/qinysong/article/details/1179480 java 乱码详解__jsp中pageEncoding.charset=UTF -8&quo ...
- I - Doing Homework again
I - Doing Homework again Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...