The Balance

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 135 Accepted Submission(s): 88
 
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
HDU 2007-Spring Programming Contest
 
Recommend
lcy
 
/*
题意:给出n个砝码的质量,让你求出在[1,s]范围内不能组成的质量,s是质量总和,这个题不一样的地方是天平两边都可以放砝码 初步思路:可以看成一个背包问题,每个取或不取,但是这个题有一个新的状态,就是
*/
#include<bits/stdc++.h>
using namespace std;
int v[];
int dp[];//dp[i]表示i金额能组成或不能组成
int vis[];//记录一下能组成的金额
int n;
int s=;
void init(){
memset(vis,,sizeof vis);
memset(dp,,sizeof dp);
s=;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
init();
for(int i=;i<=n;i++){
scanf("%d",&v[i]);
s+=v[i];
}
vis[]=;
for(int i=;i<=n;i++){
memset(dp,,sizeof dp);
for(int j=;j<=s;j++){
if(vis[j]){//j金额能组成
dp[j+v[i]]=;//加上当前金额那么也是可以的
dp[abs(j-v[i])]=;//减去这个金额的也是可以的
}
}
for(int j=;j<=s;j++){
if(dp[j]) vis[j]=;
}
}
int res=;
for(int i=;i<=s;i++)
if(!vis[i])
res++;
printf("%d\n",res);
if(res==) continue;
int f=;
for(int i=;i<=s;i++){
if(!vis[i]){
if(f==){
printf("%d",i);
f=;
}else{
printf(" %d",i);
}
}
}
printf("\n");
}
return ; }

The Balance的更多相关文章

  1. Sample a balance dataset from imbalance dataset and save it(从不平衡数据中抽取平衡数据,并保存)

    有时我们在实际分类数据挖掘中经常会遇到,类别样本很不均衡,直接使用这种不均衡数据会影响一些模型的分类效果,如logistic regression,SVM等,一种解决办法就是对数据进行均衡采样,这里就 ...

  2. LB(Load balance)负载均衡集群--{LVS-[NAT+DR]单实例实验+LVS+keeplived实验} 菜鸟入门级

    LB(Load balance)负载均衡集群 LVS-[NAT+DR]单实例实验 LVS+keeplived实验 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一 ...

  3. Balance - 七夕悠然

    想争取一个月至少一篇博客的,还是没搭上七月的末班车.两个小妹妹来上海看我了,工作上又有点儿忙,充分利用所有时间了,还是没有挪出时间来写东西,貌似写东西也要时机一样,需要在可以静静思考的时候,再加上有淡 ...

  4. Java-集合=第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: List list = new ArrayList(); list.add(new A

    第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得 ...

  5. java异常处理:建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount),当取款的数额大于存款时,抛出InsufficientFundsException,取款数额为负数,抛出NagativeFundsException,如new Bank(100),

    建立exception包,建立Bank类,类中有变量double  balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount ...

  6. UVa 673 Parentheses Balance -SilverN

    You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...

  7. POJ1837 Balance[分组背包]

    Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13717   Accepted: 8616 Descript ...

  8. UVa 673 Parentheses Balance

    一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...

  9. A feature in Netsuite Reports > Financial > Balance Sheet

    最新版本的Customize balance sheet page Left side > Layout > Add Reference Row Then in right side, y ...

  10. POJ 3142 The Balance

    Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...

随机推荐

  1. css预处理语言--让你的css编写更加简单方便

    CSS预处理语言之一-------LESS Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. Less 可以运行在 Nod ...

  2. AngularJS 框架

    AngularJS 通过 指令 扩展了 HTML,且通过 表达式 绑定数据到 HTML. [Angular JS表达式]  1.Angular JS使用双{{}}绑定方式.用于将表达式的内容输出到页面 ...

  3. 个人从源码理解angular项目在JIT模式下的启动过程

    通常一个angular项目会有一个个模块(Module)来管理各自的业务,并且必须有一个根模块(AppModule)作为应用的入口模块,整个应用都围绕AppModule展开.可以这么说,AppModu ...

  4. java核心卷轴之泛型程序设计

    本文根据<Java核心卷轴>第十二章总结而来,更加详细的内容请查看<Java核心卷轴> 1. 泛型类型只能是引用类型,不可以使用基本数据类型. 2. 类型变量含义 E : 集合 ...

  5. day01:study HTTP协议

    总结: 1.对web客户端和web服务器之间的通讯有了基本原理有了简单理解. 2.对http协议有了相关概念的建立 3.B/S C/S 两种形式 4.搭建tomcat服务器的环境,相关配置(虚拟目录 ...

  6. JQuery上传插件Uploadify详解及其中文按钮解决方案 .

    Uploadify有一个参数是 buttonText 这个无论你怎么改都不支持中文,因为插件在js里用了一个转码方法把这个参数的值转过码了,解码的地方在那个swf文件里,看不到代码,所以这条路不行. ...

  7. WPF使用资源字典组织资源

    转载:http://blog.163.com/wangzhenguo2005@126/blog/static/371405262010111413321728/     首先在解决方案资源管理器中添加 ...

  8. openvswitch 2.7 安装过程记录 总结

    envswitch 2.7 安装过程记录 总结 安装思路是参考文档: http://docs.openvswitch.org/en/latest/intro/install/general/#obta ...

  9. SQLyog快捷键汇总

    Ctrl+M   创建一个新的连接Ctrl+N   使用当前设置新建连接Ctrl+F4   断开当前连接 对象浏览器 F5   刷新对象浏览器(默认)Ctrl+B   设置焦点于对象浏览器 SQL 窗 ...

  10. Gradle sync failed 异常

    今天开发过程中出现如下异常 Gradle sync failed: Connection timed out: connect. If you are behind an HTTP proxy, pl ...