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. 计算Fisher vector和VLAD

    This short tutorial shows how to compute Fisher vector and VLAD encodings with VLFeat MATLAB interfa ...

  2. java读取文件并获得文件编码,转换为指定编码的工具类代码

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...

  3. there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

    建表语句: create table test_table(   id integer not null auto_increment primary key,   stamp_created tim ...

  4. Visual Studio 2015官方社区版/专业版/专业版下载地址

    Visual Studio 2015官方社区版/专业版/专业版下载地址 以下 Visual Studio 2015 社区版/专业版/专业版资源都是官方MSDN原版下载资源,统一为ISO格式镜像,使用解 ...

  5. insert-delete-getrandom-o1

    // 参考了下面一些讨论的解法 // https://discuss.leetcode.com/topic/53235/java-with-hashtable-arraylist/2 class Ra ...

  6. 【pyhon】理想论坛爬虫1.08

    #------------------------------------------------------------------------------------ # 理想论坛爬虫1.08,用 ...

  7. oracle 给用户赋表空间

    alter user fortune_test quota unlimited on data01;

  8. 如何用代码组织多个Storyboard(故事板)

    1. 新建一个Storyboard取名为OtherStoryboard.storyboard 2. 使用下面代码加载 UIStoryboard *newStoryboard = [UIStoryboa ...

  9. MySQL查询不区分大小写的sql写法

    MySQL查询不区分大小写的sql写法 mysql查询默认是不区分大小写的 如: select * from some_table where str=‘abc'; select * from som ...

  10. Node使用淘宝 NPM 镜像

    npm install -g cnpm --registry=https://registry.npm.taobao.org之后可以通过cnpm来安装node模块cnpm install [name]