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 ...
随机推荐
- Vuex基础-State
官方地址:https://vuex.vuejs.org/zh/guide/state.html 由于 Vuex 的状态存储是响应式的,从 store 实例中读取状态最简单的方法就是在计算属性中返回某个 ...
- ibator自动代码生成
首先,强烈推荐一篇文章,介绍的特详细 http://www.iteye.com/topic/821983 1. 插件安装 http://blog.csdn.net/rchm8519/article/d ...
- background-position设置
设置背景图片的位置:background-position:x y; 其中x和y可以为百分比也可以为像素
- Python简单线程间通信
本节主要举一个简单的线程间通信的例子,利用线程安全的数据结构queue.Queue保存线程间通信的内容, import queue from threading import Thread from ...
- python逻辑运算(not,and,or)总结
逻辑运算 1.在没有()的情况下not优先级高于and,and优先级高于or,即优先级关系为()>not>and>or,同一优先级从左往右计算 总结:a or b : 如果a = 0 ...
- 【操作系统作业-lab4】 linux 多线程编程和调度器
linux多线程编程 参考:https://blog.csdn.net/weibo1230123/article/details/81410241 https://blog.csdn.net/skyr ...
- Element-ui组件--pagination分页
一般写后台系统都会有很多的列表,有列表就相应的要用到分页,根据项目中写的几个分页写一下我对分页的理解,就当是学习笔记了. 这是Element-ui提供的完整的例子 <template> ...
- POJ:2229-Sumsets(完全背包的优化)
题目链接:http://poj.org/problem?id=2229 Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissio ...
- Smail 中的一些点
smali中所有操作都需要经过寄存器, 本地寄存器以v开头, 参数寄存器以p开头, 非static方法中p0是this 没有-object后缀的操作指令表示操作的对象是基本类型 invoke-dire ...
- 使用.gitignore忽视项目中的文件/文件夹
在项目开发的过程中,我们经常需要IDE来提高编程效率.然而,不同的IDE会生成各种各样的临时文件.在项目生命周期中,我们往往不需要关注这类文件的变更记录,因而我们是不需要将它们加入到源代码管理器中. ...