HDU 1709 母函数天平问题 可出现减法的情况 The Balance
The Balance
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6652 Accepted Submission(s): 2730
you are asked to measure a dose of medicine with a balance and a number
of weights. Certainly it is not always achievable. So you should find
out the qualities which cannot be measured from the range [1,S]. S is
the total quality of all the weights.
input consists of multiple test cases, and each case begins with a
single positive integer N (1<=N<=100) on a line by itself
indicating the number of weights you have. Followed by N integers Ai
(1<=i<=N), indicating the quality of each weight where
1<=Ai<=100.
each input set, you should first print a line specifying the number of
qualities which cannot be measured. Then print another line which
consists all the irrealizable qualities if the number is not zero.
1 2 4
3
9 2 1
2
4 5
#include<stdio.h>
#include<string.h>
#include<math.h>
int num[];
int ans[];
int c[],temp[];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
memset(num,,sizeof(num));
memset(c,,sizeof(c));
memset(ans,,sizeof(ans));
memset(temp,,sizeof(temp));
int total=;
for(int i=;i<n;i++){
scanf("%d",&num[i]);
total+=num[i];
}
for(int i=;i<=num[];i+=num[])
c[i]=;
for(int i=;i<n;i++){
for(int j=;j<=total;j++){
for(int k=;k+j<=total&&k/num[i]<=;k+=num[i]){///注意《=1
temp[j+k]+=c[j];
temp[(int)fabs(j-k)]+=c[j];//注意此刻应当考虑负值的情况
} }
for(int ii=;ii<=total;ii++)
c[ii]=temp[ii]; } int cnt=;
for(int i=;i<=total;i++){
if(!c[i]){
cnt++;
ans[cnt]=i;
}
}
printf("%d\n",cnt);
for(int i=;i<=cnt;i++){
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
}
return ;
}
HDU 1709 母函数天平问题 可出现减法的情况 The Balance的更多相关文章
- The Balance HDU - 1709 母函数(板子变化)
题意: 现在你被要求用天平和一些砝码来量一剂药.当然,这并不总是可以做到的.所以你应该找出那些不能从范围[1,S]中测量出来的品质.S是所有重量的总质量. 输入一个n,后面有n个数,表示这n个物品的质 ...
- *HDU 1709 母函数
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1028 母函数 一个数有几种相加方式
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...
- hdu 1709 The Balance(母函数)
题意: 有一个天平.有N个砝码.重量分别是A1...AN. 问重量[1..S]中有多少种重量是无法利用这个天平和这些砝码称出来的. S是N个砝码的重量总和. 思路: 对于每一个砝码来说,有三种:不放, ...
- 组合数学 - 母函数的运用 --- hdu 1709 :The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2082 母函数模板题
找单词 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1171 Big Event in HDU(母函数)
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...
- 杭电1171 Big Event in HDU(母函数+多重背包解法)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- MCV 的几种表单提交方式
一,MVC HtmlHelper方法 Html.BeginForm(actionName,controllerName,method,htmlAttributes){} 其中actionName ...
- background-position设置
设置背景图片的位置:background-position:x y; 其中x和y可以为百分比也可以为像素
- 键盘遮挡控件(textfield/textview.......)
采用的是通知的常规方式 // 解决键盘遮挡问题//选择didShow是因为需要键盘的高度//选择willHide是因为视图frame重置需要优先于键盘消失,否则表现得不连贯 [[NSNotificat ...
- Linux自带mariadb卸载
MySQL安装过程中报错: dpkg: regarding mysql-community-server_5.6.39-1debian9_i386.deb containing mysql-commu ...
- 侯捷《C++面向对象开发》——动手实现自己的复数类
前言 最近在看侯捷的一套课程<C++面向对象开发>,刚看完第一节introduction之后就被疯狂圈粉.感觉侯捷所提及所重视的部分也正是我一知半解的知识盲区,我之前也写过一些C++面向对 ...
- oracle之bitmap索引
oracle常见的索引是BTree索引和Bitmap索引. BTree索引特点: 默认索引 适合大量增删改查 不能用or操作符 适合高基数的列(即唯一值多) 创建sql:create index li ...
- node服务端渲染(完整demo)
简介 nodejs搭建多页面服务端渲染 技术点 koa 搭建服务 koa-router 创建页面路由 nunjucks 模板引擎组合html webpack打包多页面 node端异步请求 服务端日志打 ...
- JavaScript - 库 jQuery
测试 JavaScript 框架库 - jQuery 引用JQuery 如需测试JavaScript库,您需要在网页中引用它. 为了引用某个库,请使用<script>标签,其src属性设置 ...
- 【linux】【指令】systemctl 指令部分解读
systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --hel ...
- [Codeforces958A2]Death Stars (medium)(字符串+hash)
Description 题目链接 Solution 这里用类似hash的方法将判断2个矩阵是否相同的时间降为O(m),总时间复杂度为O(m3) Code #include <cstdio> ...