The Balance

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4497    Accepted Submission(s): 1808

Problem Description
Now 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
The 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.
 
Output
For 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.
 
Sample Input
3
1 2 4
3
9 2 1
 
Sample Output
0
2
4 5
 
Source
 
Recommend
lcy
 
 //对每个砝码可以不用,也可以放到左边或右边。。。。。

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,m;
int a[];
int c1[],c2[];
const int cc=; int main()
{
while(scanf("%d",&n)!=EOF)
{
int m=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
m+=a[i];
} memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2)); for(int i=-a[];i<=a[];i+=a[])
{
c1[i+cc]=;
} for(int i=;i<=n;i++)
{
for(int j=-m;j<=m;j++)
{
for(int k=-a[i];k+j<=m&&k<=a[i];k+=a[i])
{
c2[k+j+cc]+=c1[j+cc];
}
}
for(int j=-m;j<=m;j++)
{
c1[j+cc]=c2[j+cc];
c2[j+cc]=;
}
} int aas[]={};
int ans=;
for(int i=;i<=m;i++)
{
if(c1[i+cc]||c1[-i+cc]) ;
else
{
aas[ans]=i;
ans++;
}
} printf("%d\n",ans);
for(int i=;i<ans;i++)
{
if(i==)
printf("%d",aas[i]);
else
printf(" %d",aas[i]);
}
if(ans)
putchar(); } return ;
}

HDOJ 1709 The Balance(母函数)的更多相关文章

  1. 组合数学 - 母函数的运用 --- hdu 1709 :The Balance

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. 【HDOJ】1709 The Balance

    母函数,指数可以为1也可以为-1,扩大指数加消减发现TLE,于是采用绝对值就过了. #include <stdio.h> #include <string.h> #define ...

  3. hdu 1709 The Balance(母函数)

    题意: 有一个天平.有N个砝码.重量分别是A1...AN. 问重量[1..S]中有多少种重量是无法利用这个天平和这些砝码称出来的. S是N个砝码的重量总和. 思路: 对于每一个砝码来说,有三种:不放, ...

  4. The Balance(母函数)

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. hdu_1790_The Balance(母函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意:给你一些砝码,让你输出1—sum中不能称出的重量 题解:直接上母函数,在合并括号的时候有加 ...

  6. hdu 1709 The Balance

    母函数的特殊情况,左右两边都可以放,如样例1,2,9 母函数为(1+x+1/x)*(1+x^2+1/x^2)*(1+x^9+1/x^9) 化简为(1+x+x^2)*(1+x^2+x^4)*(1+x^9 ...

  7. HDU 1709 The Balance( DP )

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDOJ 2079 选课时间(母函数)

    选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. emlog模板制作帮助手册

    emlog基本模板文件 必须文件: main.css: CSS(样式表)文件 log_list.php: 日志列表页模板 echo_log.php: 日志页模板 page.php: 页面(page)模 ...

  2. How to get Financial Dimension Value from Worker Position[AX2012]

    To get financial dimension value from worker position, add a new method in hcmWorker Table with scri ...

  3. Python学习教程(learning Python)--3.2 if-else分支语句

    if-else分支语句结构的特点是当conditon条件满足时,执行if下的语句块,当condition条件不满足时执行else下的语句块,也就是说根据条件来控制让某些语句执行,某些语句不被执行. i ...

  4. activiti

    http://activiti.org/designer/archived/  eclipse plugin

  5. flask 开发记录

    from flask import request 判断method方式 request.method  'POST', ‘GET’ 获取form内容 request.form['form_name' ...

  6. angularjs2 学习笔记(四) 路由

    angular2路由是管理angular2应用内部导航的一个重要内容,在angular应用中,很多的组件是通过组合完成一个复杂的应用,不可避免的是我们常会在视图间切换,那么这是就需要使用路由来管理视图 ...

  7. [quote ]ffmpeg, gstreamer, Raspberry Pi, Windows Desktop streaming

    [quote ]ffmpeg, gstreamer, Raspberry Pi, Windows Desktop streaming http://blog.pi3g.com/2013/08/ffmp ...

  8. 学Lua(上)

    学Lua(上) 在很多游戏中,脚本语言是不可或缺的一部分,很多游戏都使用到了Lua,js,python一类的脚本,脚本语言可以在很多方面给开发进程带来帮助.脚本语言可以作为初始化文件读入变量和游戏数据 ...

  9. ORA-12154:TNS:无法解析指定的连接标识符

    ORA-12154:TNS:无法解析指定的连接标识符 1问题的描述 Oracle11g server 64bit服务器端安装在Windows Server2008 Enterprise上,安装Orac ...

  10. VS2010在C#头文件中添加文件注释的方法

    步骤: 1.VS2010 中找到安装盘符(本人安装目录在D盘,所以以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\I ...