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. 《精通Ext JS 》

    <精通Ext JS > 基本信息 原书名:Mastering Ext JS 作者: (巴西)Loiane Groner 译者: 卢俊祥 丛书名: 图灵程序设计丛书 出版社:人民邮电出版社 ...

  2. 【BZOJ】【3670】【NOI2014】动物园

    KMP算法 其实就像题面描述的那样……主要还是KMP算法的基础上搞一些DP(递推)之类…… 随便yy一下就可以得到50分了,因为num数组跟next的关系还是很密切的…… f[i]=f[next[i] ...

  3. Android组件之BroadCast简单实践

    作为Android的四大组件之一,没有理由不介绍一下BroadCast,BroadCast中文简单翻译就是广播,前阵子浙江某大学的啦啦操,广场舞的大妈,其中大妈和学生从喇叭和音响上听到的声音就是事件源 ...

  4. idea启动崩溃问题

    idea启动崩溃问题 内存已经给到1024m了: 注意到项目比较大,有个参数ReservedCodeCasheSize,把这个修改为1024m, 学习了:https://www.cnblogs.com ...

  5. mysql存储引擎简析

    一.常见存储引擎特性 Innodb 具有提交.回滚和崩溃恢复能力的事务安全.支持外键.使用mvcc以及行锁来提供事务支持,因此支持高并发.适用于写频繁,并发率高的应用. Myisam 不支持事务和灾难 ...

  6. Discuz常见小问题-如何修改网站标题title

    在全局-SEO设置中,找到论坛的title修改即可

  7. linux可视化桌面安装

    [root@VM_193_201_centos ~]# yum grouplist Loaded plugins: fastestmirror, langpacks There is no insta ...

  8. 微信小程序开发者工具下载地址

    下载地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

  9. ZH奶酪:Ubuntu14.04 安装Android SDK(SDK tools only)

    1.安装JDK(我安装的是Oracle的,而不是openjdk) jdk目录:usr/lib/jvm/java-7-oracle/bin/java 2.下载Android-SDK,在下边的网页选择对应 ...

  10. remote: ERROR: missing Change-Id in commit message footer

    remote: ERROR: missing Change-Id in commit message footer [摘要:git 提交到近程版本库失足:remote: ERROR: missing ...