[BZOJ2667][cqoi2012]模拟工厂
[BZOJ2667][cqoi2012]模拟工厂
试题描述
输入
输出
输出仅一行,为最大总收入。输出保证在32位带符号整数范围内。
输入示例
输出示例
数据规模及约定
n ≤ 15,ti ≤ 105,gi ≤ 109,mi ≤ 109
题解
发现 n 很小,我们可以 2n 枚举。然后检验答案时贪心。
首先明确,一段时间内如果提高生产力和生产的时间分别固定,那么一定是先提高生产力然后再生产最优。
如果当前有 p 的生产能力,并且已经处理完了前 i-1 个任务,那么我们可以算出对于第 i~n 个任务,算出当前时间到该任务还有多长时间(令这个时间长度为 Ti),算出第 i 到该任务总共需要生产多少产品(令这个产品数为 Gi),那么设 x 为提高生产力所用的时间可以列出不等式 (x + p)(Ti - x) ≥ Gi(就是一个开口向下的抛物线在一条水平直线的上方的部分),显然这样一个不等式的解集是一个区间 [li, ri];那么现在有一个神奇的结论,取所有 ri 中最小的就是最优的方式,这个我也不知道怎么证。。。。。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 20
#define oo 2147483647
#define LL long long int n;
struct Ord {
int t;
LL g, m;
Ord() {}
Ord(int _1, LL _2, LL _3): t(_1), g(_2), m(_3) {}
bool operator < (const Ord& t) const { return this->t < t.t; }
} os[maxn], get[maxn], gt[maxn]; int getans(LL p, LL t, LL g) {
LL A = -1, B = t - p, C = t * p - g;
LL delta = B * B - 4.0 * A * C;
if(delta < 0) return -1;
double x = (-(double)B - sqrt((double)delta)) / (2.0 * A);
return (int)x;
} int main() {
n = read();
for(int i = 0; i < n; i++) {
int a = read(), b = read(), c = read();
os[i] = Ord(a, b, c);
} sort(os, os + n);
int all = (1 << n) - 1;
LL ans = 0;
for(int i = 0; i <= all; i++) {
int cnt = 0, ct = 0;
for(int j = 0; j < n; j++) if(i >> j & 1) get[++cnt] = os[j];
get[cnt+1].t = -1;
for(int j = 1; j <= cnt; j++)
if(get[j].t == get[j+1].t) get[j+1].g += get[j].g, get[j+1].m += get[j].m;
else gt[++ct] = get[j];
gt[0].t = 0;
int p = 1; LL pro = 0, sum = 0;
for(int j = 1; j <= ct; j++) {
int x = oo; LL G = 0;
for(int k = j; k <= ct; k++)
G += gt[k].g, x = min(x, getans(p, gt[k].t - gt[j-1].t, G - pro));
pro += ((LL)x + p) * (gt[j].t - gt[j-1].t - x) - gt[j].g;
if(x < 0){ sum = -1; break; }
sum += gt[j].m; p += x;
}
// printf("%lld\n", sum);
ans = max(ans, sum);
}
printf("%lld\n", ans); return 0;
}
[BZOJ2667][cqoi2012]模拟工厂的更多相关文章
- [BZOJ2667][cqoi2012]模拟工厂 贪心
2667: [cqoi2012]模拟工厂 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 367 Solved: 184[Submit][Status] ...
- [CQOI2012]模拟工厂 题解(搜索+贪心)
[CQOI2012]模拟工厂 题解(搜索+贪心) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1327574 链接题目地址:洛谷P3161 BZOJ P26 ...
- P3161 [CQOI2012]模拟工厂
传送门 先枚举选择哪些订单,然后转为判定是否可行 在能完成的情况下肯定是花越多时间提高生产力越优 我们设可以有\(x\)单位时间来提高生产力,那么如果当前离下一个订单的时间为\(T\)时,这个订单要\ ...
- 洛谷 题解 P3161 【[CQOI2012]模拟工厂】
本蒟蒻又双叒叕被爆踩辣! 题目链接 Solution: 这题又是一道贪心.. 数据范围: n<=15 ti<=100,000 gi<=10^9 mi<=10^9 这里就可以看到 ...
- LUOGU P3161 [CQOI2012]模拟工厂 (贪心)
传送门 解题思路 贪心,首先因为\(n\)比较小,可以\(2^n\)枚举子集.然后判断的时候就每次看后面的如果用最大生产力生产能不能达成目标,解一个二次函数. 代码 #include<iostr ...
- [BZOJ2667][cqoi2012][kcoj]模拟工厂
题目描述 Description 有一个称为“模拟工厂”的游戏是这样的:在时刻0,工厂的生产力等于1.在每个时刻,你可以提高生产力或者生产商品.如果选择提高生产力,在下一个时刻时工厂的生产力加1:如果 ...
- 贪心(qwq)习题题解
贪心(qwq)习题题解 SCOI 题解 [ SCOI2016 美味 ] 假设已经确定了前i位,那么答案ans一定属于一个区间. 从高位往低位贪心,每次区间查找是否存在使此位答案为1的值. 比如6位数确 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- python mock基本使用
什么是mock? mock在翻译过来有模拟的意思.这里要介绍的mock是辅助单元测试的一个模块.它允许您用模拟对象替换您的系统的部分,并对它们已使用的方式进行断言. 在Python2.x 中 mock ...
随机推荐
- Tree POJ - 174
点分模板题 都快改的跟题解一模一样了2333333 #include<cstdio> #include<cstring> #include<algorithm> u ...
- 针对谷歌默认最小字体12px的正确解决方案
利用css3的缩放,其最终大小就是:12px * 0.9(缩放比例) = 10.8px; 居然行得通.但回头一想,这么写的话,IE7 IE8会不会不兼容,还是12px呢?不出所料,果然不兼容.此时,又 ...
- UWP Windows10开发更新磁贴和动态更新磁贴
下面将介绍两种方式如何在windows10 uwp开发中如何更新应用磁贴: 实际上windows的磁贴就是用xml实现的,你只需要创建相应格式的xml就可以实现动态磁贴了 一,手动更新磁贴 二,轮询更 ...
- logging模块基础3
1.logging模块的日志级别 CRITICAL = 50 #FATAL = CRITICAL ERROR = 40 WARNING = 30 #WARN = WARNING INFO = 20 D ...
- struts 2.5 There is no Action mapped for namespace [/] and action name [user_find] associated with context path [/struts2_crm].
遇到了这个错误. There is no Action mapped for namespace [/] and action name [user_find] associated with con ...
- Git ---创建和切换分支
······································································"天下武功,唯快不破" git分支: g ...
- Node.js——url模块
url模块通过api可以将get提交的参数方便的提取出来
- Regular Expression Flavors
Perl https://perldoc.perl.org/perlre.html PCRE http://www.pcre.org/current/doc/html/pcre2syntax.html ...
- 整合Activiti Modeler到业务系统(或BPM平台)
http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler.html 1. 为什么要整合 Activiti 5.10版本把 ...
- Dynamic type checking and runtime type information
动态类型的关键是将动态对象与实际类型信息绑定. See also: Dynamic programming language and Interpreted language Dynamic type ...