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. android 插件化框架speed-tools

    项目介绍: speed-tools 是一款基于代理模式的动态部署apk热更新框架.插件化开发框架: speed-tools这个名字主要指的快速迭代开发工具集的意思. 功能与特性: 1.支持Androi ...

  2. {ubuntu}乱七八糟重命名为1 2 3.....png

    i=; for f in *.png; do mv "$f" ${i}.png; ((i++)); done 网上找了个测试的数据集,发现读取时候,要重命名一下 一片帖子问了类似的 ...

  3. Does Little'law really applicable to apply performance model now?

    上次提到Little定律, 我也解释过它跟另外一个公式有一些内在的关系,但是其实我自己对LL在当前复杂架构系统中到底是怎么应用的也没有完整的想法,于是我在Linkedin上把这个问题抛了出来,没有想到 ...

  4. python中中括号中的负数

    >>> a="a,b,c,d,e">>> a.split(",")[0:2]['a', 'b']>>> a ...

  5. selenium-Python之鼠标事件

    通过click()来模拟鼠标的单击操作,鼠标还具有鼠标右击,双击,悬停甚至鼠标拖动等功能.在webdriver中,将这些鼠标操作方法封装在ActionChains类提供. ActionChains类提 ...

  6. Tunneling cannot be enabled without the local_ip bound to an interface on the host. Please configure local_ip 192.168.30.71 on the host interface to be used for tunneling and restart the agen

    按照官方文档配置linux bridge 会出现一下问题 Tunneling cannot be enabled without the local_ip bound to an interface ...

  7. CPP-基础:strcpy之于C++(

    以下对strcpy函数错误的是? char atr1[]="string"; ]; char *str3; char *str4="sting"; A.strc ...

  8. quartz测试类

    package demo.mytest; import java.text.ParseException; import org.quartz.CronTrigger;import org.quart ...

  9. 变色龙启动MAC时,错误信息“ntfs_fixup: magic doesn't match:”的解决办法

    如下是变色龙启动的bdmesg,解决办法就是用mac的磁盘管理器,对ntfs分区进行检验修复.需要安装ntfs的驱动支持. 实在不行,就删除调整过大小的分区,重新用Windows的磁盘管理器重新分区. ...

  10. 洛谷P1000 超级玛丽游戏

    这道题很简单,就是原样输出,只不过写起来有点恶心!!! code: #include<stdio.h> int main() { printf( " ********\n&quo ...