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 ...
随机推荐
- Ubuntu 12.04 the system is running in low-graphics mode
1.出现问题如图所示: 2.解决方案: Ctrl + Alt + F1 df -h 输入密码,到了这一步,也是可以使用terminal,那么没有图形界面也是可以的 cd /etc/X11 sudo c ...
- C#浏览器中在线操作文档
源码地址:https://github.com/SeaLee02/FunctionModule 文件夹 UploadFiles/WebDemo/COM/OnlineEdit.aspx 就是源码 用 ...
- matlab vs联调
vs 和matlab联调,最近真的把我搞挂了要. 首先,怎么进入联调呢.在vs里先设置一下. vs:tools->attach to process,选择matlab,注意此时matlab一定是 ...
- jquery 操作DOM元素(1)
.clone() 创建一个匹配的元素集合的深度拷贝. .clone([withDataAndEvents]) withDataAndEvents (默认为false) 一个Boolean 表示是否会复 ...
- 洛谷题解:P1209 【[USACO1.3]修理牛棚 Barn Repair】
原题传送门:https://www.luogu.org/problemnew/show/P1209 首先,这是一道贪心题. 我们先来分析它的贪心策略. 例如,样例: 4 50 18 3 4 6 ...
- 用Java读取xml文件内容
在AXP中,DOM解析器是1 Document Builder类的一个实例,该实例由 DocumenBailderfactorv类负责创,步如下 DocumentBuilderFactory fa ...
- lvs+keepalived实验
一.VRRP协议与工作原理 在现实网络环境中,主机之间的通信都是通过配置静态路由或者(默认网关)来完成的,而主机之间的路由器一旦发生故障,通信就会失效,因此这种通信模式当中,路由器就成了一个单点瓶颈, ...
- HTML+CSS : 笔记整理(3 移动端布局简单了解)
流体布局:宽度用百分比,计算真实宽度用函数 : width: calc(25% - 4px); box-sizing: 1.content-box:默认计算方式 ,宽度和高度分别应用到元素的内容框.在 ...
- static作用域
当一个函数完成时,它的所有变量通常都会被删除.然而,有时候您希望某个局部变量不要被删除. 要做到这一点,请在您第一次声明变量时使用 static 关键字: <?php function myTe ...
- 裸机——LCD
1.先了解显示器们 CRT显示器 原理,使用电子轰击荧光粉实现显示. 特点,主动发光,颜色绚丽,但是大. 等离子显示器(PDP) 原理,在显示屏上排列上千个密封的小低压气体室,通过电流激发使其发出肉眼 ...