博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The Balance
阅读量:6855 次
发布时间:2019-06-26

本文共 2385 字,大约阅读时间需要 7 分钟。

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

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6404115.html

你可能感兴趣的文章
第八次会
查看>>
利用脚本打包的动态库 在打包发布时出现得问题解析 ERROR ITMS-90362等
查看>>
Tomcat安全配置规范
查看>>
Configure Dynamics 365 and Azure Service Bus Integration (using OneWay relay and listener)
查看>>
必须掌握的30种SQL语句优化
查看>>
day14-css边框以及其他常用样式
查看>>
还原数据库 提示数据在访问中,无法独占访问
查看>>
【其他】Xshell秘钥方式登陆服务器
查看>>
Codeforces 405C
查看>>
Tomcat之catalina.out日志分割
查看>>
Ubuntu下安装Matplotlib和basemap
查看>>
Fedora17 64bit 安装ORACLE 11gR2
查看>>
[转]以安装桌面体验功能为例来探索windows2012服务器管理器的新变化
查看>>
php 发送POST 请求
查看>>
angularjs四大核心特性
查看>>
售前工程师的成长---一个老员工的经验之谈(四)(转载)
查看>>
201571030329/201571030310《小学四则运算练习软件需求获取》结对项目报告
查看>>
JS数组攻略
查看>>
【高德地图Android SDK】视频教学
查看>>
scanf&scanf_s difference
查看>>