Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1
题目连接:
http://www.codeforces.com/contest/670/problem/D1
Description
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.
Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.
Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
Input
The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), 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 ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.
Output
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
Sample Input
3 1
2 1 4
11 3 16
Sample Output
4
题意
你的蛋糕需要n个原材料,你现在有k个魔法材料,魔法材料可以转化为任何材料
现在告诉你蛋糕每个材料需要多少,以及你现在有多少个
问你最多能够做出多少个蛋糕来
题解:
直接二分就好了,注意加起来会爆int
以及r给到2e9才行
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long a[maxn],b[maxn],k;
int n;
bool check(long long x)
{
    long long ans = 0;
    for(int i=1;i<=n;i++)
        if(a[i]*x-b[i]>k)return false;
    for(int i=1;i<=n;i++)
        ans+=max(a[i]*x-b[i],0LL);
    if(ans<=k)return true;
    return false;
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)scanf("%lld",&b[i]);
    long long l=0,r=2e9,ans=0;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))l=mid+1,ans=mid;
        else r=mid-1;
    }
    cout<<ans<<endl;
}Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分的更多相关文章
- 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 ... 
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
		题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ... 
- Codeforces Round #350 (Div. 2) D1
		D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ... 
- Codeforces Round #365 (Div. 2)  C - Chris and Road 二分找切点
		// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ... 
- Codeforces Round #350 (Div. 2)A,B,C,D1
		A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ... 
- Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】
		A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ... 
- Codeforces Round #540 (Div. 3)  D1. Coffee and Coursework (Easy version) 【贪心】
		任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ... 
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
		传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ... 
- Codeforces Round #542(Div. 2) D1.Toy Train
		链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ... 
随机推荐
- 浅析Postgres中的并发控制(Concurrency Control)与事务特性(上)
			转载:https://www.cnblogs.com/flying-tiger/p/9567213.html#4121483#undefined PostgreSQL为开发者提供了一组丰富的工具来管理 ... 
- trace spring
			package xx.com.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotati ... 
- dragstart drag dragend dragenter dragover dragleave drop
			dragstart drag dragend dragenter dragover dragleave drop 前端框架层出不穷,网页上的效果越来越绚丽,制作绚丽的效果的成本越来越低,其中有种拖 ... 
- java基础74 XML解析中的SAX解析相关知识点(网页知识)
			1.SAX解析工具 SAX解析工具:是Sun公司提供的,内置JDK中.org.xml.sax.* 点击查看: DOM解析相关知识:以及DOM和SAX解析的原理(区别) 2.SAX解析的 ... 
- MySQL学习笔记:repeat、loop循环
			一.repeat循环 # ---- repeat ---- DELIMITER $$ CREATE PROCEDURE test_repeat() BEGIN ; REPEAT ; UNTIL a E ... 
- afl入门学习
			一个简单的示例 安装afl wget http://lcamtuf.coredump.cx/afl.tgz tar xfz afl.tgz cd afl-xxx sudo make install 用 ... 
- CVE-2011-0104 Microsoft Office Excel缓冲区溢出漏洞 分析
			漏洞简述 Microsoft Excel是Microsoft Office组件之一,是流行的电子表格处理软件. Microsoft Excel中存在缓冲区溢出漏洞,远程攻击者可利用此 ... 
- java 基础类库之 SQLFun
			package com.exjor.webdemo; import java.sql.Timestamp; import java.util.Date; public class SQLFun { / ... 
- Web_add_cookie的作用
			1. Web_add_cookie的作用:保存Server传过来的cookie,以后的访问都会基于此cookie,直到脚本的结束. 2. 关联:服务器端返回给客户端一些动态变化的值,客户端使用这些值去 ... 
- Spring Boot 实用MyBatis做数据库操作
			前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ... 
