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 ...
随机推荐
- 前端jQuery之属性操作
属性操作主要分为四个部分:html属性操作,dom属性操作,类样式操作和值操作 HTML属性操作:属性的读取,设置,以及移除,如attr().removeAttr() DOM属性操作:属性的读取,设置 ...
- XML 对xml文件的crud的增加 create操作 增加元素 增加属性
把创建的节点挂到上一节点的最后 找到参考节点,使用insertBefore方法进行插入位置 xml添加属性使用setAttribute方法
- PBJVision 快速在应用中集成相机/拍摄功能
PBJVision 简介 PBJVision, 是一个iOS相机操作的封装库,可以让你的应用快速简单地继承相机相关功能. 项目主页: PBJVision 最新示例:点击下载 注意: 示例需要在真机上运 ...
- Redis连接工具类
Redis连接工具类 导包 测试一下(junit) package com.test; import org.junit.Test; import redis.clients.jedis.Jedis; ...
- elasticsearch-dsl聚合-1
接续上篇,本篇介绍elasticsearch聚合查询,使用python库elasticsearch-dsl进行聚合查询操作. 7.3.聚合查询 高阶概念 Buckets(桶/集合):满足特定条件的文档 ...
- 使用inotify-tools与rsync构建实时备份系统
使用inotifywait监控文件变动 inotifywait是 inotify-tools 包中提供的一个工具,它使用 inotify API 来监控文件/目录中的变动情况. 在archlinux上 ...
- pywinauto 的使用
要用python实现Windows窗口程序的自动化操作,可以用ctypes调用windowsapi来实现,还可以用pywin32+pywinauto来实现,后者是别人造的轮子. pywinauto首页 ...
- LInux操作随手笔记
一.find 的用法 实例 find / -name test.txt 就可以找到这个文件的路径(如果存在). 二.学用vi编辑器,学用rz往linux服务器上面上传文件 linux中rz 和 sz ...
- P2158 [SDOI2008] (欧拉函数
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- mysql sum 为 0 的解决方法
使用SQL语句SUM函数的时候,默认查询没有值的情况下返回的是null,而实际可能我们要用的是返回0. 解决方法:SELECT SUM(count) FROM test_table 改成: SELEC ...