HDOJ-1709-The Balance 解题报告
来源:互联网 发布:usb网络打印服务器使用 编辑:程序博客网 时间:2024/06/07 14:38
普通母函数,不错的题。题意:你需要计算一份药的剂量,现在有若干砝码,问在从1到所有砝码的质量和这段区间内有那些重量是测量不出来的。
我的解题思路:砝码并不是只放在天平的一端,可以把砝码放在天平的两端,这样两边砝码的差值就是可以测量的质量数。所以对于每一个砝码,有三种情况,放天平左边,放天平右边,以及未使用。令砝码质量为x的指数,那么构造的母函数中对于一个质量为a的项为(x^-a,1,x^a)。这样最后算出来的母函数中是有指数为负数的项的,这个可以不用管,只需要检查指数从1到砝码质量总和这个区间内那些项不存在(也就是系数为0)就可以了。
我的解题代码:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <math.h>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>using namespace std;const int N = 22001;const int M = 101;int coe[N], tmp[N];int *ncoe, *ntmp;int val[M];int n, sum;void InitRead();void DataProcess();void Generate();int main(){ while (~scanf("%d", &n)) { InitRead(); DataProcess(); } return 0;}void InitRead(){ sum = 0; ncoe = &coe[11000]; ntmp = &tmp[11000]; for (int i=1; i<=n; ++i) { scanf("%d", &val[i]); sum += val[i]; } memset(coe, 0, sizeof(coe)); memset(tmp, 0, sizeof(tmp)); return;}void DataProcess(){ int ans = 0; int ansnum[10001]; Generate(); for (int i=1; i<=sum; ++i) { if (ncoe[i] == 0) ansnum[ans++] = i; } printf("%d\n", ans); for (int i=0; i<ans; ++i) { printf("%d%c", ansnum[i], i == ans - 1 ? '\n' : ' '); } return;}void Generate(){ ncoe[0] = 1; for (int i=1; i<=n; ++i) { for (int j=-10000; j<10001; ++j) { if (ncoe[j] == 0) continue; for (int k=-1; k<=1; ++k) { ntmp[k * val[i] + j] += ncoe[j]; } } memcpy(coe, tmp, sizeof(coe)); memset(tmp, 0, sizeof(tmp)); } return;}
0 0
- HDOJ-1709-The Balance 解题报告
- HDOJ_1709 The Balance 解题报告
- 解题报告:HDU_1709 The Balance
- HDOJ 1709-The Balance【模拟】
- POJ 2142 The Balance 解题报告(模线性方程)
- hdoj 1709 The Balance(母函数)
- HDoj-1709-The Balance-母函数
- HDOJ 1709 The Balance(母函数)
- The Balance hdoj 1709 (母函数初学)
- hdoj 1709 The Balance(母函数)
- HDOJ 1004 Let the Balloon Rise解题报告
- HDOJ 1032 The 3n + 1 problem解题报告
- HDOJ 1028 Ignatius and the Princess III解题报告
- HDOJ 1010 Tempter of the Bone解题报告
- HDOJ 1029:Ignatius and the Princess IV 解题报告
- HDOJ 1010:Tempter of the Bone 迷宫问题 解题报告
- HDOJ 4006The kth great number 解题报告
- HDOJ-2680-Choose the best route 解题报告
- 蓝桥杯真题——硬币方案
- 【Android】自己写的轻量级安卓网络框架——能够控制网络连接,支持缓存
- sizof类对象,类对象的内存
- RevitAPI: 如何在详图构件上创建尺寸标注
- 如何编写自定义标签?具体流程与分析(自定义标签快速入门)
- HDOJ-1709-The Balance 解题报告
- 类中默认的成员函数
- JAVA中int、String的类型转换
- iOS单例模式的实现方法总结
- mac 版本下载编译chromium最新源码
- ubuntu14.04 codeblocks 13.12 字体
- zepto.js 自定义打包集成其他模块构建流程
- select2 bootstrap 简单使用
- php 回调函数