zoukankan      html  css  js  c++  java
  • hdu 1709 母函数变形

    1. #include <stdio.h>
    2. #include <string.h>
    3. #include <stdlib.h>
    4. #define MAX 10010
    5. int c1[MAX], c2[MAX], num[110];
    6. /* 题目大意: 给你n种砝码,从1到n中砝码的重量和其中不能称出多少种重量,输出不能称出的总数和类别*/
    7. int main()
    8. {
    9. int n;
    10. while( scanf("%d", &n)!=EOF )
    11. {
    12. memset(num, 0, sizeof(num) );
    13. memset(c1, 0, sizeof(c1) );
    14. memset(c2, 0, sizeof(c2) );
    15. int total = 0;
    16. for(int i=0; i<n; i++) //重量输入
    17. {scanf("%d", &num[i]); total+=num[i];}
    18. //for(int i=0; i<=total; i++)
    19. //c1[i] = c2[i] = 0;
    20. c1[0] = 1; //第一个括号,重量为0的
    21. for(int i=0; i<n; i++)
    22. {
    23. for(int j=0; j<=total; j++)
    24. {
    25. c2[j] |= c1[j]; //否能称得,自己砝码的重量
    26. if(num[i] + j <=total) //重量和是否大于总重量
    27. c2[j+num[i]] |= c1[j]; //重量和
    28. c2[abs(j-num[i])] |= c1[j]; //重量差
    29. }
    30. for(int j=0; j<=total; j++) //一次循环赋值
    31. {c1[j] = c2[j]; c2[j] = 0;}
    32. }
    33. int count = 0;
    34. for(int i=0; i<=total; i++) //查找能否称得的重量
    35. {
    36. if(!c1[i])
    37. c2[count++] = i;
    38. }
    39. printf("%d ", count);
    40. for(int i=0; i<count-1; i++)
    41. printf("%d ", c2[i]);
    42. if(count) printf("%d ", c2[count-1]);
    43. }
    44. return 0;
    45. }
    46. /*
    47. Problem Description
    48. 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.
    49. Input
    50. 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.
    51. Output
    52. 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.
    53. Sample Input
    54. 3
    55. 1 2 4
    56. 3
    57. 9 2 1
    58. Sample Output
    59. 0
    60. 2
    61. 4 5
    62. */





    附件列表

    • 相关阅读:
      [转化率预估-1]引言
      MATLAB 的输入输出命令
      MATLAB R2018a 输入中文却显示方框问号的问题
      支持向量机-SVM 学习
      MATLAB R2018a 安装教程
      【DeepLearning】用于几何匹配的卷积神经网络体系结构
      Alias Method for Sampling 采样方法
      关于机器学习的充分统计量
      java.lang.NullPointerException 空指针异常问题
      Eclipse导入项目时出错提示 project is missing required library
    • 原文地址:https://www.cnblogs.com/sober-reflection/p/030bcb6e395767a11e6c170a46e258f7.html
    Copyright © 2011-2022 走看看