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 ...
随机推荐
- 第32章 TIM—高级定时器—零死角玩转STM32-F429系列
第32章 TIM—高级定时器 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fire ...
- SpringBoot中使用配置文件
一般都是把xml配置文件转换为@Bean的模式,如果非要使用xml配置文件,方式如下: /** * 将配置文件引入springboot */ @Configuration @ImportResourc ...
- JDK 动态代理 讨债实例
现弄一个讨债接口 package cn.itcast.g_dongtaidaili; public interface Taozhai { void taozhai(); } 再弄一个讨债实现类 pa ...
- 精心收集的48个JavaScript代码片段,仅需30秒就可理解
源文链接 :https://github.com/Chalarangelo/30-seconds-of-code#anagrams-of-string-with-duplicates 该项目来自于 G ...
- 深入浅出:了解JavaScript的ES6、ES7新特性
参照阮一峰博客:http://es6.ruanyifeng.com/#README es6常见题:https://blog.csdn.net/qq_39207948/article/details/8 ...
- 【杂题总汇】UVa-1336 Fixing the Great Wall
[UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了
- 网页更换主题以及绘制图形js代码实现
HTML代码实现: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- 分享spring、spring boot、spring cloud一些学习资源,从基础知识到项目实战
1.spring注解驱动开发,学习spring boot和spring cloud必备知识 链接: https://pan.baidu.com/s/1xhULzLlpkERhoMi1G5Lgfg 密码 ...
- Mysql:case when then end 的用法
0.创建一张数据表 表名为 test_when_case CREATE TABLE `test_when_case` ( `id` int(11) unsigned NOT NULL AUTO_INC ...
- 单片机入门学习笔记8:STM32单片机使用
经常会在某个QQ群里看见某人的QQ昵称的名字"不会32绝不改名",其实无论会不会,之后名称都改了. STM32单片机在我看来就三部分组成:各部分的初始化,中断的使用,Main函数内 ...