C. Anton and Making Potions 贪心 + 二分
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 贪心 + 二分的更多相关文章
- 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 ...
- Codeforces 734C Anton and Making Potions(枚举+二分)
题目链接:http://codeforces.com/problemset/problem/734/C 题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,第一类周瑜有m种,每种 ...
- CodeForce-734C Anton and Making Potions(贪心+二分)
CodeForce-734C Anton and Making Potions C. Anton and Making Potions time limit per test 4 seconds m ...
- 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 ...
- 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 ...
- 二分算法题目训练(三)——Anton and Making Potions详解
codeforces734C——Anton and Making Potions详解 Anton and Making Potions 题目描述(google翻译) 安东正在玩一个非常有趣的电脑游戏, ...
- [二分] Codefoces Anton and Making Potions
Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- Anton and Making Potions
Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input sta ...
- poj 2782 Bin Packing (贪心+二分)
F - 贪心+ 二分 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description ...
随机推荐
- AttributeError: module 'tensorflow' has no attribute 'sub'
官方的例子:运行之后出现以下错误 # 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = ...
- codeforces B. Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/304/B 题目意思:给出两个日期,需要算出这两个日期之间有多少日. 细心模拟就可以了.特别要注意的是,两个 ...
- tensorflow sigmoid_cross_entropy_with_logits 函数解释
tf.nn.sigmoid_cross_entropy_with_logits(_sentinel=None,labels=None, logits=None, name=None) sigmoid_ ...
- 编译Thrift
按照 https://syslint.com/blog/tutorial/how-to-install-apache-thrift-on-ubuntu-14-04/ 进行, 编译时出现错误 make[ ...
- 【C】论‘\r’和'\n'的纯粹性
- Linux-Nginx和NFS
1 虚拟化 查看系统信息 cat /proc/meninfo cat /proc/cpuinfo 其中 flags里面的信息可以查看该cpu是否支持虚拟化 flags上有vmx svm等表示可以虚拟化 ...
- 【CQ18高一暑假前挑战赛2】标程
[昨晚打校赛,5个小时打完很累了,所以搞忘出题了...对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大] [A:bush博弈] #include<bits/st ...
- Quicklz压缩算法
以前对压缩算法一无所知,只是知道哈弗曼编码能做这种事情,但是感觉这样的方法奇慢无比.昨天下午看了下号称世界上最快的压缩算法Quicklz,对压缩的基本思路有了一定的了解.一般的压缩程序的要求读入文件之 ...
- 洛谷P3385判负环——spfa
题目:https://www.luogu.org/problemnew/show/P3385 两种方法,dfs和bfs: 一开始写的dfs,要把dis数组初值赋成0,这样从一个连着负边的点开始搜: 在 ...
- poj2226Muddy Fields——二分图匹配
题目:http://poj.org/problem?id=2226 把行连通块作为左部点,列连通块作为右部点,行列连通块有相交的格子就连边: 则问题转化为求最小点覆盖,即最大匹配. 代码如下: #in ...