题目链接:http://codeforces.com/problemset/problem/734/C

题目大意:要制作n个药,初始制作一个药的时间为x,魔力值为s,有两类咒语,
第一类周瑜有m种,每种咒语使制作一个药的时间变成a[i],花费b[i]的魔力,
第二类咒语有k种,每种咒语瞬间产生c[i]个药,花费d[i]的魔力,c[i]和d[i]都是不递减的,
求最短时间内产生n个药的时间。
解题思路:
因为c[i]和d[i]都是不降的,所以可以枚举a[i],然后二分查找花费小于t-b[i]的第二类咒语。
注意这里要用upper_bound()而不能用lower_bound(),比如
10 12
82 82
前者会找到12,而后者会找到10。

代码:

 #include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=2e5+;
const int INF=0x3f3f3f3f;
const double eps=1e-; LL n,m,k,x,s;
LL a[N],b[N],c[N],d[N]; int main(){
FAST_IO;
cin>>n>>m>>k>>x>>s;
for(int i=;i<=m;i++){
cin>>a[i];
}
for(int i=;i<=m;i++){
cin>>b[i];
}
for(int i=;i<=k;i++){
cin>>c[i];
}
for(int i=;i<=k;i++){
cin>>d[i];
} LL ans=x*n; //初始化为不用魔法所需时间
a[]=x; for(int i=;i<=m;i++){
//魔力值不够
if(b[i]>s) continue;
LL t=s-b[i];
int pos=upper_bound(d+,d++k,t)-d;
pos--;
ans=min(ans,a[i]*(n-c[pos]));
}
cout<<ans<<endl;
return ;
}

Codeforces 734C 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(二分)

    Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass ...

  3. Codeforces gym101612 L.Little Difference(枚举+二分)

    传送:http://codeforces.com/gym/101612 题意:给定一个数n(<=1e18),将n分解为若干个数的成绩.要求这些数两两之间的差值不能大于1. 分析: 若n==2^k ...

  4. Codeforces H. Prime Gift(折半枚举二分)

    题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...

  5. C. Anton and Making Potions 贪心 + 二分

    http://codeforces.com/contest/734/problem/C 因为有两种操作,那么可以这样考虑, 1.都不执行,就是开始的答案是n * x 2.先执行第一个操作,然后就会得到 ...

  6. 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 ...

  7. 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 ...

  8. [二分] Codefoces Anton and Making Potions

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

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

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

随机推荐

  1. Android实现透明的颜色效果(zz)

    android Button或者ImageButton背景透明状态设置 设置Button或ImageButton的背景为透明或者半透明 半透明< Button android:backgroun ...

  2. Jenkins(一)---我理解的jenkins是这样的

    1.齿轮 如果将 java / maven / ant / git / tomcat / jenkins 等等软件比喻为齿轮:如下图 两个软件在一起可以驱动另外一个软件:如下图 如果把这些软件要集成在 ...

  3. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  4. [POI2007]Zap

    bzoj 1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...

  5. java8 write file 写文件

    1.用BufferedWriter写入文件 //Get the file reference Path path = Paths.get("c:/output.txt"); //U ...

  6. Java8 新特性 Streams map() 示例

    在Java 8中stream().map(),您可以将对象转换为其他对象.查看以下示例: 1.大写字符串列表 1.1简单的Java示例将Strings列表转换为大写. TestJava8.java p ...

  7. Linux下压缩文件-1

    tar负责打包,gzip负责压缩 tar-c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的 ...

  8. fifo 上使用 select -- 转

    http://www.outflux.net/blog/archives/2008/03/09/using-select-on-a-fifo/ The right way to handle on-g ...

  9. 50、多线程创建的三种方式之实现Runnable接口

    实现Runnable接口创建线程 使用Runnable创建线程步骤: package com.sutaoyu.Thread; //1.自定义一个类实现java.lang包下的Runnable接口 cl ...

  10. 【译】第一篇 Integration Services:SSIS是什么

    本篇文章是Integration Services系列的第一篇,详细内容请参考原文. Integration Services是一种在SQL Server中最受欢迎的子系统.允许你在各种数据源之间提取 ...