The Balance

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

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
 
母函数,有左右算法....很好的题目..
思路...先选着一个点作为‘0’点,然后对左右放置之后的数组(即幂)进行右移动.....最后统计.....很吊的一道母函数呀!!,题目非常新颖.....
 #include<iostream>
#include<vector>
#include<cstring>
#define maxn 20003
#define gong 10000
using namespace std;
int c1[maxn],c2[maxn];
int save[maxn];
int main()
{
int n,i,sum,j,k,count;
while(cin>>n)
{
vector<int>arr(n);
memset(c1,,sizeof(c1));
memset(c2,,sizeof c2);
memset(save,,sizeof save);
count=sum=;
for(i=;i<n;i++)
{
cin>>arr[i];
sum+=arr[i];
}
for(i=-arr[];i<=arr[];i+=arr[])
{
c1[i+gong]=;
}
for(i=;i<n;i++)
{
for(j=-sum;j<=sum;j++)
{
for(k=-arr[i];k<=arr[i]&&k+j<=sum;k+=arr[i])
{
c2[k+j+gong]+=c1[j+gong];
}
} for(j=-sum+gong;j<=sum+gong;j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
int ans=;
for(j=;j<=sum;j++)
{
if(c1[j+gong]==||c1[gong-j]==)
{
save[ans++]=j;
}
}
cout<<ans<<endl;
if(ans)
{
for(i=;i<ans;i++)
{
if(i==)
cout<<save[i];
else
cout<<" "<<save[i];
}
cout<<endl;
}
}
return ;
}

HDUOJ ----1709的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)

    题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...

  5. Cogs 1709. [SPOJ705]不同的子串 后缀数组

    题目:http://cojs.tk/cogs/problem/problem.php?pid=1709 1709. [SPOJ705]不同的子串 ★★   输入文件:subst1.in   输出文件: ...

  6. codevs 1709 钉子和小球

    1709 钉子和小球 1999年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果题目描述 Description有一个三角形木板 ...

  7. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  8. 1709: [Usaco2007 Oct]Super Paintball超级弹珠

    1709: [Usaco2007 Oct]Super Paintball超级弹珠 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 339  Solved:  ...

  9. windows10版本1709 在桌面和文件中点击右键,会引起卡顿

    windows自动升级到1709版本后出现的问题,而之前是没有这种问题的. 最终解决办法:(需要设置注册表) 运行:快捷键Win+R regedit 路径:可直接复制后粘贴+回车 HKEY_CLASS ...

随机推荐

  1. linux统计文件夹内文件数

    for dir in `find ./ -type d ` ;do echo -n "$dir "  ;find $dir  -type f | wc -l ;echo " ...

  2. DAHON 美国大行

    DAHON美国大行1982年创立于美国加州,多年来一直率先推动环保的代步工具——折叠自行车.创新是大行的生命,从韩氏兄弟发明了全世界第一辆小到能够放进火车座椅底下的折叠自行车起,大行就开启了不断向前的 ...

  3. JConsole详解

    一.JConsole是什么 从Java 5开始 引入了 JConsole.JConsole 是一个内置 Java 性能分析器,可以从命令行或在 GUI shell 中运行.您可以轻松地使用 JCons ...

  4. 【BZOJ】【3262】陌上花开

    树套树 orz zyf 这题的思路……算是让我了解到了树套树的一种用途吧 三维...第一维排序,第二维树状数组,第三维treap 具体实现就是每个树状数组的节点保存一颗treap,然后就可以查询了. ...

  5. jQuery多媒体播放器插件jQuery Media Plugin使用方法

    jQuery Media Plugin是一款基于jQuery的网页媒体播放器插件,它支持大部分的网络多媒体播放器和多媒体格式,比如:Flash, Windows Media Player, Real ...

  6. [Web前端]由cookies安全说开去

    在Web应用中,Cookie很容易成为安全问题的一部分.从以往的经验来看,对Cookie在开发过程中的使用,很多开发团队并没有形成共识或者一定的 规范,这也使得很多应用中的Cookie成为潜在的易受攻 ...

  7. C#汉字转拼音,可识别多音字,带声调,提供正向、逆向、双向分词算法的小程序

    用C#写了个汉字转拼音的小工具,和网上大部分工具不同,这个通过分词算法,解决了多音字的问题,并且提供声调,可开可关. 如题,用"银行 行不行 行家说了算"举例,如果转拼音却不能识别 ...

  8. matlab中find函数的使用说明

    matlab中如何统计一个矩阵M中零的个数 size(find(M==0),1) 原文:http://blog.sina.com.cn/s/blog_707b64550100rbh3.html fin ...

  9. ubuntu Server 设置主机静态 ip地址

    ubuntu Server 设置主机静态 ip地址 1:先输入 ifconfig 查看当前网络配置 2:然后关闭 eth0 网卡 sudo ifdown eth0 3:配置静态ip sudo vim ...

  10. The jQuery HTML5 Audio / Video Library (jQuery jPlayer插件给你的站点增加视频和音频功能)

    http://jplayer.org/ The jQuery HTML5 Audio / Video Library jPlayer is the completely free and open s ...