hdu1709 The Balance
来源:互联网 发布:centos6网络配置 编辑:程序博客网 时间:2024/05/14 16:32
The Balance
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4597 Accepted Submission(s): 1842
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
31 2 439 2 1
Sample Output
024 5
Source
HDU 2007-Spring Programming Contest
Recommend
lcy
#include<stdio.h>#include<math.h>int c2[100000],c1[100000];int main(){int i,j,k,s,m,x,n,a[105];while(scanf("%d",&n)!=EOF){for(i=0,s=0;i<n;i++){scanf("%d",&a[i]);s+=a[i];//s用来求和,也就是最多可能出现的所有重量个数}for(i=0;i<s;i++){c2[i]=0;//标记的,看i是否已出现}for(i=0,k=0,m=0;i<n;++i){if(c2[a[i]-1]==0)//如果这个砝码本身还没有被加进这个数组,那就把它加进去{c1[m]=a[i];c2[a[i]-1]++;m++;}for(j=0;j<k;++j)//小于k是为了避免一个砝码被重复用来组合{x=a[i]+c1[j];//与前面所有的已有数据作和if(c2[x-1]==0)//如果新产生的数在以前没出现{c1[m]=x;//假如数组c2[x-1]++;m++;}x=abs(a[i]-c1[j]);//与前面所有数据做差,因为可能与其他砝码分放在两边if(x>0&&c2[x-1]==0)//这就和上面的作用一样,x>0是为了防止数组越界
{c1[m]=x;c2[x-1]++;m++;}}k=m;//m是加入当前玛法后产生不同重量的总数}printf("%d\n",s-k);//k是最终所有可能出现的重量,s是总重量也是最多可能出现的个数if(k!=s){for(j=0,i=0;i<s;i++){if(c2[i]==0)if(j!=0)//这一步和下面的主要是格式控制printf(" %d",i+1);else {j++;printf("%d",i+1);}}printf("\n");}}return 0;}
- hdu1709 The Balance
- hdu1709 The Balance
- HDU1709 The Balance 【母函数】
- HDU1709 The Balance【母函数】
- HDU1709 The Balance,母函数套题
- HDU1709 The Balance(母函数)
- hdu1709(The Balance)用java会超时
- HDU1709 The Balance(母函数)
- The Balance (hdu1709) 母函数
- hdu1709 The Balance (放入+取出 01背包)
- HDU1709:The Balance(类01背包 & 母函数)
- hdu1709 the blance
- hdu1709
- HDU1709
- hdu1709
- The Balance
- The Balance
- The Balance
- 浅析处理器技术与编程模型的发展趋势
- Plus One
- 2012 工作总结
- 重复代码(克隆代码)的几个概念与类型
- 黑马程序员---GUI(图形化界面)
- hdu1709 The Balance
- Segmentation fault (core dumped)
- 假前学习总结
- 对照Jingle的XMPP stanza理解Libjingle的几个关键数据结构
- error: 'for' loop initial declarations are only allowed in C99 mode
- hdu 1722 Cake
- 黑马程序员---网络编程
- ZOJ 3666 Alice and Bob(博弈 sg 函数入门)
- 线段树单点更新个人总结