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

题目链接: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。

代码:

 1 #include<bits/stdc++.h>
 2 #define lc(a) (a<<1)
 3 #define rc(a) (a<<1|1)
 4 #define MID(a,b) ((a+b)>>1)
 5 #define fin(name)  freopen(name,"r",stdin)
 6 #define fout(name) freopen(name,"w",stdout)
 7 #define clr(arr,val) memset(arr,val,sizeof(arr))
 8 #define _for(i,start,end) for(int i=start;i<=end;i++)
 9 #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
10 using namespace std;
11 typedef long long LL;
12 const int N=2e5+5;
13 const int INF=0x3f3f3f3f;
14 const double eps=1e-10;
15
16 LL n,m,k,x,s;
17 LL a[N],b[N],c[N],d[N];
18
19 int main(){
20     FAST_IO;
21     cin>>n>>m>>k>>x>>s;
22     for(int i=1;i<=m;i++){
23         cin>>a[i];
24     }
25     for(int i=1;i<=m;i++){
26         cin>>b[i];
27     }
28     for(int i=1;i<=k;i++){
29         cin>>c[i];
30     }
31     for(int i=1;i<=k;i++){
32         cin>>d[i];
33     }
34
35     LL ans=x*n;                //初始化为不用魔法所需时间
36     a[0]=x;
37
38     for(int i=0;i<=m;i++){
39         //魔力值不够
40         if(b[i]>s) continue;
41         LL t=s-b[i];
42         int pos=upper_bound(d+1,d+1+k,t)-d;
43         pos--;
44         ans=min(ans,a[i]*(n-c[pos]));
45     }
46     cout<<ans<<endl;
47     return 0;
48 }

原文地址:https://www.cnblogs.com/fu3638/p/9104406.html

时间: 2024-08-26 00:24:12

Codeforces 734C Anton and Making Potions(枚举+二分)的相关文章

[二分] Codefoces Anton and Making Potions

Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next le

codeforces 289B - Polo the Penguin and Matrix 二分+dp

题意:给你一个序列,每一次可以对序列里面任意数+d 或者 -d 问你最少多少步能够使得数列里面所有的数相等 解题思路:从 1 - 10000 枚举这个数,二分找数列中小于等于它的最大的那个数,然后求前缀和以后刻意快速求出差值和的绝对值,差值和/d 就是我们所求数. 解题代码: 1 // File Name: 289b.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月29日 星期二 22时33分11秒 4 5 #include<vecto

Codeforces Round #262 (Div. 2) 总结:二分

B. Little Dima and Equation 思路:本来前两题都很快做出来的,然后觉得ranting应该可以增加了.然后觉得代码没问题了,又想到了一组cha人的数据,然后就锁了,然后刚锁就被别人cha了看了代码才发现尼玛忘了判断小于10^9了,然后C反正想了好多种方法都不会就没心情了,就这样rating又降了 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #in

hdu4430之枚举+二分

Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2549    Accepted Submission(s): 522 Problem Description Today is Yukari's n-th birthday. Ran and Chen hold a celebration party

CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] Description Give you n packs, each of it has a value v and a weight w. Now you should find some packs, and the total of these value is max, total of

hdu 4430 Yukari&#39;s Birthday 枚举+二分

注意会超long long 开i次根号方法,te=(ll)pow(n,1.0/i); Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3262    Accepted Submission(s): 695 Problem Description Today is Yukari's n-th birt

Eqs 折半枚举+二分查找 大水题

Eqs 题目抽象:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 (*),给出a1,a2,a3,a4,a5.    ai属于[-50,50]. 求有多少序列   x1,x2,x3,x4,x5 ,xi属于 [-50,50]-{0}. 思路:折半枚举+二分查找 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #inclu

UVA10277 - Boastin&#39; Red Socks(枚举+二分)

UVA10277 - Boastin' Red Socks(枚举+二分) 题目链接 题目大意:现在有m只红袜子,n只黑袜子,这样总袜子total = n + m;现在给你p, q,确定n和m,使得从这些袜子中取两只都是红袜子的概率等于p/q:如果没有这样的n和m满足要求输出impossible; 解题思路:m *(m - 1) / (total * (total - 1)) = p /q; 那么我们只需要枚举total,就可以解到m.但是会有精度误差,貌似有解决的办法,但是觉得没法理解.后面看了

poj 3977 Subset 枚举+二分

首先分成一半2^17和2^18,并且把其中一半变成相反数,然后枚举一半二分查找另一半,在找到的位置前后也找找. 这里用到了二级排序,有很多细节要处理,不多说了. 巨坑的一个地方就是,不能用系统的abs,要自己手写,简直坑死.. #include<cstdio> #include<algorithm> #include<iostream> #include<map> using namespace std; typedef long long ll; stru