周赛Problem 1108: 蛋糕(二分)
1108: 蛋糕
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 17 Solved: 4
Description
Input
每组数据第一行输入两个整数,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: 蛋糕(二分)的更多相关文章
- 周赛Problem 1021: 分蛋糕(埃拉托斯特尼筛法)
Problem 1021: 分蛋糕 Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: %lld ...
- 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 ...
- 周赛Problem 1025: Hkhv love spent money(RMQ)
Problem 1025: Hkhv love spent money Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger ...
- hpu第六次周赛Problem F
Problem F Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- HDU 5008 Boring String Problem(后缀数组+二分)
题目链接 思路 想到了,但是木写对啊....代码 各种bug,写的乱死了.... 输出最靠前的,比较折腾... #include <cstdio> #include <cstring ...
- Problem 1108 - 淼·诺贝尔
#include<iostream> #include<vector> #include<algorithm> using namespace std; struc ...
- 【wikioi】1108 方块游戏(模拟)
http://wikioi.com/problem/1108/ 这题有点变态,因为他根本没有策略! 还是说这题不是实时的?反正这题很变态,是在一个时间段同时消除所有的行列斜边,同一时间!!!!!! 所 ...
- POJ 3273 Monthly Expense 二分枚举
题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...
- hiho一下 第三十七周 二分查找之k小数
题目链接:http://hihocoder.com/contest/hiho37/problem/1 , 简单二分. 算法: 题目即为求一个无序数组数组中第k小的数,由于数据量太大,排序是会超时的. ...
随机推荐
- java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal问题解决
使用Maven构建项目并加载spring配置文件时,报如下异常 Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTrav ...
- UVA 10735 Euler Circuit (最大流)
题意:求混合图的欧拉路径. 一句话总结:网络流,最主要在于建图,此题是将出度则是和流量联系在了一起,用最大流来调整边的指向. 分析: 这题的困难之处在于无向边只能用一次,相当于一个方向未定的有向边. ...
- v-if与v-show的区别与选择
v-if与v-show的区别与选择 官网给的区别 v-if 是“真正”的条件渲染,因为它会确保在切换过程中条件块内的事件监听器和子组件适当地被销毁和重建. v-if也是惰性的:如果在初始渲染时条件 ...
- call和apply方法的异同
基本作用:改变对象的执行上下文. this指向执行上下文.(执行环境) this指向的永远是调用该方法的对象 function func(){ this.a=1; console.log(this.a ...
- spring中常用的注解
使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package ...
- 标准C中字符串分割方法
◆ 使用strtok函数分割. 原型:char *strtok(char *s, char *delim); strtok在s中查找包含在delim中的字符并用NULL('\0')来替换,直到找遍整个 ...
- 基于PassThru的NDIS中间层驱动程序扩展
基于PassThru的NDIS中间层驱动程序扩展 独孤求真 概要:开发一个NDIS驱动是一项相对复杂的工作,这一方面是由于核心驱动本身 ...
- git 的.gitignore
# vs code .vscode # Logs *.log #npm node_modules
- UVa-101-木块问题
这题用vector比较好写,我们设置对应的几个函数,然后进行相应的操作来简化代码,这样才不易出错. 对于输入和操作来说我们经分析之后,可以看到最后一个操作时最原始的操作也就是不需要还原任意一个堆任意高 ...
- 纯 CSS 创作一个小球绕着圆环盘旋的动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gKxyWo 可交互视频 ...