The Balance
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 |
|
Sample Output
0 |
|
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的更多相关文章
- Sample a balance dataset from imbalance dataset and save it(从不平衡数据中抽取平衡数据,并保存)
有时我们在实际分类数据挖掘中经常会遇到,类别样本很不均衡,直接使用这种不均衡数据会影响一些模型的分类效果,如logistic regression,SVM等,一种解决办法就是对数据进行均衡采样,这里就 ...
- LB(Load balance)负载均衡集群--{LVS-[NAT+DR]单实例实验+LVS+keeplived实验} 菜鸟入门级
LB(Load balance)负载均衡集群 LVS-[NAT+DR]单实例实验 LVS+keeplived实验 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一 ...
- Balance - 七夕悠然
想争取一个月至少一篇博客的,还是没搭上七月的末班车.两个小妹妹来上海看我了,工作上又有点儿忙,充分利用所有时间了,还是没有挪出时间来写东西,貌似写东西也要时机一样,需要在可以静静思考的时候,再加上有淡 ...
- 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; 要求完善设计,使得 ...
- java异常处理:建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount),当取款的数额大于存款时,抛出InsufficientFundsException,取款数额为负数,抛出NagativeFundsException,如new Bank(100),
建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount ...
- UVa 673 Parentheses Balance -SilverN
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- POJ1837 Balance[分组背包]
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13717 Accepted: 8616 Descript ...
- UVa 673 Parentheses Balance
一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...
- A feature in Netsuite Reports > Financial > Balance Sheet
最新版本的Customize balance sheet page Left side > Layout > Add Reference Row Then in right side, y ...
- POJ 3142 The Balance
Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...
随机推荐
- js时间戳和日期字符串相互转换
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- java复习要点(一)------- java语言的特点、java的工作原理、配置环境变量、java命令的使用
一.java语言的特点: (1)简单并面向对象 (2)鲁棒并安全: java语言在编译及运行程序时,都要进行严格的检查,防止不匹配问题的发生.如果引用一个非法类型,或执行一个非法类型操作,java减肥 ...
- 第6章 Overlapped I/O, 在你身后变戏法 ---Win32 文件操作函数 -2
Win32 之中有三个基本的函数用来执行 I/O,它们是: i CreateFile() i ReadFile() i WriteFile() 没有另外 ...
- 第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ---线程优先权(Thread priority)
有没有过这样的经验?你坐在你的车子里,目的地还在好几公里之遥,而时间已经很晚了.你拼命想告诉那些挡住你去路的人们,今天这个约会对你是多么多么重要,能不能请他们统统--呃--滚到马路外?很不幸,道路系统 ...
- Monit : 开源监控工具介绍
· Monit 简介 Monit是一个轻量级(500KB)跨平台的用来监控Unix/linux系统的开源工具.部署简单,并且不依赖任何第三方程序.插件或者库. Monit可以监控服务器进程.文件.文件 ...
- 个人工作中ssd、audio python脚本总结
1.os.system(cmd)或者os.popen(cmd)调用外部命令 cmd中需要注意特殊字符的转义功能,如: USBSTOR\DISK&VEN_GENERIC-&PROD_SD ...
- iOS开发注意事项(一)
1.OC的消息机制与C++等的函数(方法)有很大的不同,OC在运行时所执行的代码由运行环境来决定,而C++等则由编译器决定.如果调用的函数是多态的,C++在运行时要按照虚方法表来查出到底执行哪个函数, ...
- HDU2048 HDU2049 组合数系列 错排
HDU1465HDU2048HDU2049#include<cstdio> #include<cstdlib> #include<iostream> #includ ...
- 关于http与https区别
http与https: http叫超文本传输协议,信息为明文传输.https是具有安全性的传输协议,是由http+ssl层,需要到ca申请证书,一般需要费用.信息为加密传输,需要验证用户身份.二者的端 ...
- Layer弹层组件 二次扩展,项目中直接使用。
/************************ Layer扩展 ****************************/ /* * Layer弹出Alert提示框 * @param messag ...