Codefroces D2. Magic Powder - 2(二分)
http://codeforces.com/problemset/problem/670/D2
http://codeforces.com/problemset/problem/670/D1
1 second
256 megabytes
standard input
standard output
The term of this problem is the same as the previous one, the only exception — increased restrictions.
The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie.
The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
1 1000000000
1
1000000000
2000000000
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
0
3 1
2 1 4
11 3 16
4
4 3
4 3 5 6
11 12 14 20
3
二分模板
#include<iostream>
using namespace std;
int binary_search(int a[],int l,int r,int k)
{
int mid,ans;
while(l<=r)
{
mid=(l+r)>>1;
if(a[mid]<=k){
l=mid+1;
ans=mid;
}
else r=mid-1;
}
return ans;//也可ans+n;
}
int main()
{
int a[11]={1,2,4,7,7,7,7,8,10,11};
cout<<binary_search(a,0,9,4)<<endl;
return 0;
}
题解
#include<iostream>
#include<cstdio>
using namespace std;
long long a[],b[];
int main()
{
long long n,k,i;
scanf("%lld%lld",&n,&k);
for(i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=;i<n;i++)
{
scanf("%lld",&b[i]);
}
long long l=,r=;
while(l<=r)
{
long long mid=(l+r)>>;
long long sum=;
for(i=;i<n;i++)
{
if(mid*a[i]>b[i]) sum+=(mid*a[i]-b[i]);
if(sum>k) break;
}
if(sum<=k) l=mid+;
else r=mid-;
}
printf("%lld",l-);
return ;
}
Codefroces D2. Magic Powder - 2(二分)的更多相关文章
- codeforces 350 div2 D Magic Powder - 2 二分
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- D2 Magic Powder -1/- 2---cf#350D2(二分)
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- CodeForces 670D2 Magic Powder - 2 (二分)
题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...
- CodeForces 670D2 Magic Powder 二分
D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...
- Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- Codeforces 670D1. Magic Powder - 1 暴力
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
随机推荐
- 11g Oracle Rac安装(基于linux6)可能出现的问题
11g Oracle Rac安装(基于linux6)可能出现的问题汇总: 7)使用"yum"命令执行节点的自动配置失败. 修改一下 /etc/resolv.conf,添加: nam ...
- Camera Calibration 相机标定:原理简介(五)
5 基于2D标定物的标定方法 基于2D标定物的标定方法,原理与基于3D标定物相同,只是通过相机对一个平面进行成像,就可得到相机的标定参数,由于标定物为平面,本身所具有的约束条机,相对后者标定更为简单. ...
- hdu5105Math Problem(分类讨论)
题目链接: huangjing 题目: 思路: 给出的是一个方程,首先讨论最高项系数. 1:a==0&& b==0 那么函数就是线性的.直接比較端点就可以. 2 a==0& ...
- [数位dp] bzoj 3209 花神的数论题
题意:中文题. 思路:和普通数位dp一样,这里转换成二进制,然后记录有几个一. 统计的时候乘起来就好了. 代码: #include"cstdlib" #include"c ...
- JAVA学习(五):Java面向对象编程基础
Java面向对象编程基础 面向对象(Object oriented programming,OOP)技术是一种强有力的软件开发方法,它採用数据抽象与信息隐藏技术,来使软件开发简单化,以达到代码重用的目 ...
- sass05 数据类型,数据运算
/*! 数字类型 */ $n1: 1.2; $n2: 12; $n3: 14px; p{ font-size: $n3; } /*! 字符串类型*/ $s1: container; $s2: 'con ...
- js 实现 水仙花数
水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身.(例如:1^3 + 5^3+ 3^3 = 153) <!DOCTYPE html><html ...
- User-defined types
We have used many of Python’s built-in types; now we are going to define a new type. As an example, ...
- CURRENMONTH TAG in Automation Framework
/** * @param input * <CURRENTMONTH><CURRENTMONTH+1> * @return Month "MM" */ pr ...
- BZOJ 4269 高斯消元求线性基
思路: 最大: 所有线性基异或一下 次大: 最大的异或一下最小的线性基 搞定~ //By SiriusRen #include <cstdio> #include <algorith ...