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. MYSQL数据库表中字段追加字符串内容

    $sql="update parts set p_notes=concat(p_notes,'{$p_notes}') where p_id={$p_id}"; parts为表名 ...

  2. 使用WIF实现单点登录Part III —— 正式实战

    我们接下来的demo将包括以下的工程: SiteA —— 基于.net framework 4.5的MVC 4程序,使用WIF 4.5的SDK,第一个RP SiteB —— 基于.net framew ...

  3. Learning Scrapy笔记(一)- Scrapy简单介绍

    Scrapy简述 Scrapy十一个健壮的,用来从互联网上抓取数据的web框架,Scrapy只需要一个配置文件就能组合各种组件和配置选项,并且Scrapy是基于事件(event-based)的架构,使 ...

  4. Java入门到精通——工具篇之Maven概述

    为接手gxpt准备已经快一个月了从SSH2-->EJB-->环境搭建-->Maven的构建.下面就带领大家初始Maven 一.什么是Maven. Maven是一个垮平台的项目管理工具 ...

  5. DB2递归查询

    斐波纳契数列,又称黄金分割数列,指的是这样一个数列:1.1.2.3.5.8.13.21.……在数学上,斐波纳契数列以如下被以递归的方法定义:F0=0,F1=1,Fn=F(n-1)+F(n-2)(n&g ...

  6. uninstall 11.2.0.3.0 grid & database in linux 5.7

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  7. AppCan移动平台,开发者是这样用的……

    随着生活节奏的加快,每天各种压力山大,难免产生心理问题.然而穷的都要吃土了,又不想面对陌生人,怎么办? 近日,AppCan开发者樊星阳“一夜爆红”,引起猎云网的持续关注.起因是这样的,樊星阳利用App ...

  8. swift学习初步(三)--控制流操作

    在上一篇博客里面,我谈到了swift里面的一些基本类型以及相关的操作,相信你看了之后一定会觉得其实swift也不难嘛.好吧,这篇博客里面要谈的一些高级操作,可能会让你有点头疼了. 好了,废话不多说了, ...

  9. Go语言工程结构

    Go是一门推崇软件工程理念的编程语言. Go的代码必须放在GOPATH目录下,它应该包含三个子目录: src:用于以代码包的形式组织并保存Go源码文件.应该分为三类:库源码文件.命令源码文件.测试源码 ...

  10. 如何让webapi只返回json格式数据

    最近脑子不好用,总记不住事,以前搞过让webapi只返回json格式的数据,今天有人问我又突然想不起了,后来总结一下,备忘一下,大概有下面几种处理方式 1.在WebApiConfig类的Registe ...