1108: 蛋糕

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 17  Solved: 4

Description

杨神打代码打得有点疲倦,于是他想要开始做蛋糕。若某一种蛋糕需要有n种材料,然后每种材料需要ai 克,杨神手里有每种材料bi克,而且因为杨神有多年积蓄的神奇粉末,每一克神奇粉末可以代替任何一种材料1克。然后他仙子啊纠结,自己的这些材料加上神奇粉末,最多可以做多少个蛋糕。就靠你们了。

Input

有多组数据不超过110组。
每组数据第一行输入两个整数,n,k(1 ≤ n ≤ 100 000, 1 ≤ k ≤ 1e9)--代表这个蛋糕需要n种材料,以及杨神有k克神奇粉末。
第二行有n个数a1, a2, ..., an (1 ≤ ai ≤ 1e9) 代表每种材料需要ai克。
第三行也是n个数b1, b2, ..., bn (1 ≤ bi ≤ 1e9)代表杨神现在拥有的材料。

Output

每组数据输出一个整数,代表最多能做多少个蛋糕。

Sample Input

1 1000000000
1
1000000000
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1

Sample Output

2000000000
0

周赛的题目……本来完全没想法的,问了学长发现是智障了把n看成1e9了以为绝对不能暴力。一开始把判断合法函数写里面且忘记了是用ans记录答案而不是直接输出mid智障WA多次。写成check()函数就好了,做的第一道二分答案的题目,还是有规律可循的。

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define INF 0x3f3f3f3f
#define MM(x) memset(x,0,sizeof(x))
#define MMINF(x) memset(x,INF,sizeof(x))
const double PI=acos(-1.0);
const int N=100010;
using namespace std;
typedef long long LL;
LL n,k;
LL a[N],b[N];
bool check(LL mid,LL temp)
{
for (int i=1; i<=n; i++)
{
if(b[i]<mid*a[i])
{
if(mid*a[i]-b[i]<=temp)
temp-=(mid*a[i]-b[i]);
else
return false;;
}
}
return true;
}
int main(void)
{
ios::sync_with_stdio(false);
int i,j;
LL L,R;
while (cin>>n>>k)
{
for (i=1; i<=n; i++)
cin>>a[i];
for (i=1; i<=n; i++)
cin>>b[i];
L=0,R=2e9+9;
LL mid,temp,ans;
int flag;
while (L<=R)
{
temp=k;
mid=(L+R)>>1;
if(check(mid,temp))
{
ans=mid;
L=mid+1;
}
else
R=mid-1;
}
cout<<ans<<endl;
}
return 0;
}

周赛Problem 1108: 蛋糕(二分)的更多相关文章

  1. 周赛Problem 1021: 分蛋糕(埃拉托斯特尼筛法)

    Problem 1021: 分蛋糕 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %lld  ...

  2. Google Code Jam Round 1A 2015 Problem B. Haircut 二分

    Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barb ...

  3. 周赛Problem 1025: Hkhv love spent money(RMQ)

    Problem 1025: Hkhv love spent money Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger ...

  4. hpu第六次周赛Problem F

    Problem F Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  5. HDU 5008 Boring String Problem(后缀数组+二分)

    题目链接 思路 想到了,但是木写对啊....代码 各种bug,写的乱死了.... 输出最靠前的,比较折腾... #include <cstdio> #include <cstring ...

  6. Problem 1108 - 淼·诺贝尔

    #include<iostream> #include<vector> #include<algorithm> using namespace std; struc ...

  7. 【wikioi】1108 方块游戏(模拟)

    http://wikioi.com/problem/1108/ 这题有点变态,因为他根本没有策略! 还是说这题不是实时的?反正这题很变态,是在一个时间段同时消除所有的行列斜边,同一时间!!!!!! 所 ...

  8. POJ 3273 Monthly Expense 二分枚举

    题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...

  9. hiho一下 第三十七周 二分查找之k小数

    题目链接:http://hihocoder.com/contest/hiho37/problem/1 , 简单二分. 算法: 题目即为求一个无序数组数组中第k小的数,由于数据量太大,排序是会超时的. ...

随机推荐

  1. printf 遇到bash重定向

    在printf之前添加:setvbuf(stdout,NULL,_IONBF,0);设置缓冲区为空. 在每句printf之后添加:fflush(stdout); 方法一: 1 2 3 4 5 6 7 ...

  2. Android 验证码倒计时两种方案

    使用 第一种方案:自定义控件 1.在布局中使用 <?xml version="1.0" encoding="utf-8"?> <Relativ ...

  3. java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/xxx/lib/arm/liblame.so: has text relocations

    最近在写本地录音转码过程中引入了liblame.so,我这边用了不同系统版本的手机测试本地录音都没有出现问题,但是有一天,同事在测试的时候,出现了以下错误: 09-13 17:32:29.140 26 ...

  4. uvm_subscriber——告诉她我们来过

    Subscribers are basically listeners of an analysis port. They subscribe to a broadcaster and receive ...

  5. nmon安装和使用介绍

    使用参考地址:百度中搜索 nmon 博客园 使用文档参考地址:http://nmon.sourceforge.net/pmwiki.php?n=Site.Documentation nmmon地址:h ...

  6. codevs 3278 最小m 段和问题

    时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题目描述 Description 给定 n 个整数(不一定是正整数)组成的序列,现在要求将序列分割为 m 段,每段 ...

  7. 仿天猫淘宝的ShopNC好商城原生Android 客户端源码项目

    开发环境:Android Studio 2.0 | Gradle 2.0.0最后更新:2016-04-28 简介:基于好商城V4的Android客户端 目前已完成的功能(概述): 1.启动页 -> ...

  8. tomcat配置 —— 各个目录的作用

    tomcat各目录(文件)作用 tomcat-7.0.50解压版,主目录一览: 我们可以看到主目录下有bin,conf,lib,logs,temp,webapps,work 7个文件夹,下面对他们分别 ...

  9. k8s 创建资源的两种方式【转】

    命令 vs 配置文件 Kubernetes 支持两种方式创建资源: 1. 用 kubectl 命令直接创建,比如: kubectl run nginx-deployment --image=nginx ...

  10. 多维的vector定义和初始化

    vector<vector<int> >vv(3, vector<int>(4));//这里,两个“>”间的空格是不可少的 将构造一个二维向量vv,它含有三个 ...