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. error: 'release' is unavailable: not available in automatic reference counting,该怎么解决

    编译出现错误: 'release' is unavailable: not available in automatic reference counting mode.. 解决办法: You nee ...

  2. HDU1874畅通project续 dijkstra&amp;&amp;floyd

    畅通project续 http://acm.hdu.edu.cn/showproblem.php?pid=1874 Time Limit: 3000/1000 MS (Java/Others)    ...

  3. OpenCV教程(42) xml/yaml文件的读写

    参考资料: http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html #include "opencv2/openc ...

  4. 第十四章 Executors源码解析

    前边两章介绍了基础线程池ThreadPoolExecutor的使用方式.工作机理.参数详细介绍以及核心源码解析. 具体的介绍请参照: 第十二章 ThreadPoolExecutor使用与工作机理 第十 ...

  5. SQL2005,错误 0xc00470fe 数据流任务 产品级别对于 组件“源 - 2009_txt”(1) 而言不足

    今天在将txt文件导入MSSQL2005时,出了这个错误,到网上查了一下资料,说是因为没有安装SQL 2005 SP1的原因,所以我就下载了个. 安装后,再次导入数据,OK 没问题了.http://w ...

  6. Kafka集群环境搭建(2.9.2-0.8.2.2)

    Kafka是一个分布式.可分区.可复制的消息系统.Kafka将消息以topic为单位进行归纳:Kafka发布消息的程序称为producer,也叫生产者:Kafka预订topics并消费消息的程序称为c ...

  7. 体绘制(Volume Rendering)概述之4:光线投射算法(Ray Casting)实现流程和代码(基于CPU的实现)

    转自:http://blog.csdn.net/liu_lin_xm/article/details/4850630 摘抄“GPU Programming And Cg Language Primer ...

  8. 如何监控执行的SQL语句?

    环境: SQL Server 2012. 打开SQL Server Profiler. 在菜单中选择New Trace, 连接上SQL Server. 在弹出的窗口中选择Event selection ...

  9. [Backbone] Customzing Backbone

    Convert the AppointmentForm view below to use Mustache templating. Make sure you remember to change ...

  10. Android 色彩设计理念

    色彩 色彩从当代建筑.路标.人行横道以及运动场馆中获取灵感.由此引发出大胆的颜色表达激活了色彩,与单调乏味的周边环境形成鲜明的对照. 强调大胆的阴影和高光.引出意想不到且充满活力的颜色. 色样 – 0 ...