http://codeforces.com/contest/734/problem/C

因为有两种操作,那么可以这样考虑,

1、都不执行,就是开始的答案是n * x

2、先执行第一个操作,然后就会得到一个time和left。就是你会得到一个新的用时,和一个剩下的魔法数,然后在第二个操作数中二分,二分第一个小于等于left的值,意思就是我现在还拥有left点魔法,能够买最多多少个技能的意思。

就是,看着样例一

得到的会是

time : 40s    80s  60s

left   : 79  89   59

3、同理,可以先执行第二种操作,再执行第一种操作。这就需要我们把第一种操作的东西排序了。这里用到了贪心,排序第一是按照需要的魔法数来排,第二是按照a[i]从大到小。(这里又fst,唉,一个符号)。因为这样是最优的。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e6 + ;
LL a[maxn];
LL b[maxn];
struct node {
LL c, d;
node(LL cc, LL dd) : c(cc), d(dd) {}
node() {}
bool operator < (const struct node & rhs) const {
return d < rhs.d;
}
}arr[maxn];
struct tt {
LL tim, lef;
LL id;
}ff[maxn];
struct bug {
LL a, b;
int id;
bug() {}
bug(LL aa, LL bb) : a(aa), b(bb) {}
bool operator < (const struct bug & rhs) const {
if (b != rhs.b) return b < rhs.b;
else return a > rhs.a; //这个按大排
}
}gg[maxn];
void work() {
LL n, m, k;
cin >> n >> m >> k;
LL x, limit;
cin >> x >> limit;
for (int i = ; i <= m; ++i) {
cin >> a[i];
gg[i].a = a[i];
}
for (int i = ; i <= m; ++i) {
cin >> b[i];
gg[i].b = b[i];
gg[i].id = i;
}
sort(gg + , gg + + m);
for (int i = ; i <= k; ++i) {
cin >> arr[i].c;
}
for (int i = ; i <= k; ++i) {
cin >> arr[i].d;
}
LL ans = n * x;
int lenff = ;
// cout << x << endl;
for (int i = ; i <= m; ++i) {
if (b[i] > limit) continue;
++lenff;
ff[lenff].tim = n * a[i];
ff[lenff].lef = limit - b[i];
ff[lenff].id = i;
}
// for (int i = 1; i <= lenff; ++i) {
// cout << ff[i].tim << " " << ff[i].lef << endl;
// }
for (int i = ; i <= lenff; ++i) {
ans = min(ans, ff[i].tim);
if (ff[i].lef < arr[].d) continue;
int pos = upper_bound(arr + , arr + + k, node(0L, ff[i].lef)) - arr;
pos--;
LL t = ff[i].tim - arr[pos].c * a[ff[i].id];
ans = min(ans, t);
}
lenff = ;
for (int i = ; i <= k; ++i) {
if (arr[i].d > limit) continue;
++lenff;
ff[lenff].lef = limit - arr[i].d;
ff[lenff].tim = (n - arr[i].c) * x;
ff[lenff].id = n - arr[i].c;
}
for (int i = ; i <= lenff; ++i) {
ans = min(ans, ff[i].tim);
if (ff[i].lef < gg[].b) continue;
int pos = upper_bound(gg + , gg + + m, bug(, ff[i].lef)) - gg;
pos--;
LL t = ff[i].id * a[gg[pos].id];
ans = min(ans, t);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
work();
return ;
}

C. Anton and Making Potions 贪心 + 二分的更多相关文章

  1. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  2. Codeforces 734C Anton and Making Potions(枚举+二分)

    题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种 ...

  3. CodeForce-734C Anton and Making Potions(贪心+二分)

    CodeForce-734C Anton and Making Potions  C. Anton and Making Potions time limit per test 4 seconds m ...

  4. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分

    C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...

  6. 二分算法题目训练(三)——Anton and Making Potions详解

    codeforces734C——Anton and Making Potions详解 Anton and Making Potions 题目描述(google翻译) 安东正在玩一个非常有趣的电脑游戏, ...

  7. [二分] Codefoces Anton and Making Potions

    Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  8. Anton and Making Potions

    Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  9. poj 2782 Bin Packing (贪心+二分)

    F - 贪心+ 二分 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description ...

随机推荐

  1. XML简介——可扩展标记语言(Extensible Markup Language)

    (What) XML是什么? XML指可扩展标记语言(Extensible Markup Language) 1.  XML是一种标记语言,类似HTML. 2.  XML具有自我描述性 3.  XML ...

  2. hdu-5744 Keep On Movin(思维)

    题目链接: Keep On Movin Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Oth ...

  3. poj2728 Desert King——01分数规划

    题目:http://poj.org/problem?id=2728 第一道01分数规划题!(其实也蛮简单的) 这题也可以用迭代做(但是不会),这里用了二分: 由于比较裸,不作过多说明了. 代码如下: ...

  4. for循环的一个注意点

    unsigned int i =10; for(i;i > 0; i--) { xxxxx } 因为i是unsigned int 类型的,永远不可能小于0,也就是说是个死循环了.

  5. 使用 Git 命令去管理项目的版本控制(二)

    参考 上一篇  完成本篇博客,本篇为作者原创,仅供学习参考. 本篇博文在上一篇的基础上这里记录了我的一个小模拟练习.本篇作为自己的学习笔记,也意在方便其他人的学习使用,达到分享目的.下面主要是操作截图 ...

  6. mysql:mysql安装及一些配置和图形界面介绍

    关于mysql,我使用的不多,这次记录是在学习一位大牛的demo的契机下完成的.包括前面记录到的sqlserver的一些知识点,也是在新的项目组中协助时候学习记录的.希望通过记录加深印象和帮助后来者. ...

  7. UVa 10723 Cyborg Genes (LCS, DP)

    题意:给定两行字符串,让你找出一个最短的序列,使得这两个字符串是它的子串,并且求出有多少种. 析:这个题和LCS很像,我们就可以利用这个思想,首先是求最短的长度,不就是两个字符串长度之和再减去公共的么 ...

  8. VS Supercharger插件

    一.前言 Supercharger 是 VS 的一款插件,针对代码进行优化和着色,便于观察和区分. 二.下载及安装 下载的 URL 如下:Supercharger 下载地址 点击下载,下载完成以后,那 ...

  9. Swift 4.0 中的 open,public,internal,fileprivate,private

    1.private private访问级别所修饰的属性或者方法只能在当前类里访问. 2.fileprivate fileprivate访问级别所修饰的属性或者方法在当前的Swift源文件里可以访问. ...

  10. IOS实时监控上传下载速度

    在开发中要获取网络类型是很简单的,导入Reachability直接获取状态就行了,现在我们要做一个类似下载器的那种实时把上传下载速度显示出来. 需要用到的头文件 使用Reachability 要测速度 ...