今天,开博客,,,激动,第一次啊
嗯,,先来发水题纪念一下

D1. Magic Powder - 1

 

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 alln 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.

Examples

input

3 12 1 4
11 3 16

output

4

input

4 3
4 3 5 6
11 12 14 20

output

3

Note

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

1、CodeForces 670D1

2、链接:http://codeforces.com/problemset/problem/670/D1

3、总结:

题意,给出n种做一个饼干所要的材料数,n种现有材料数,k个可变化材料,求可做多少饼干。

可暴力,也可直接二分。

小数据直接暴力

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define abs(a) ((a)>0?(a):-(a))
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
int main()
{
int n,k;
int a[],b[];
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=;i<n;i++)scanf("%d",&a[i]);
for(int i=;i<n;i++)scanf("%d",&b[i]);
int aa,flag=;
int num=;
while(k>=) //k>=0,不要k>0
{
for(int i=;i<n;i++){ //找到个数最小点,标记
if(aa>b[i]/a[i]){
flag=i;
aa=b[i]/a[i];
}
}
//下面更新记录
int bb=a[flag]-b[flag]%a[flag];
if(k<bb)break;
else {
k-=bb;
b[flag]+=bb;
aa=b[flag]/a[flag];
} }
cout<<aa<<endl;
}
return ;
}

大数据二分
参考了http://blog.csdn.net/qiuxueming_csdn/article/details/51471935

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define abs(a) ((a)>0?(a):-(a))
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
int n,k;
int a[],b[];
bool ok(LL mid)
{
LL kk=k;
for(int i=;i<n;i++){
if(a[i]*mid>b[i]){
kk-=(a[i]*mid-b[i]); }
if(kk<)return false; //mid太大,跳出; 不能放到上面if里
}
return true; //mid太小,使k有剩余
}
int main()
{
while(~scanf("%d%d",&n,&k))
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int i=;i<n;i++)
scanf("%d",&b[i]);
LL l=,r=INF;
LL num,mid;
while(l<=r)
{
mid=(l+r)>>;
if(ok(mid)){
l=mid+;
num=mid; //num要在这里赋值
}else {
r=mid-;
}
}
cout<<num<<endl;
}
return ;
}

CodeForces 670D1 暴力或二分的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces Round #404 (Div. 2) A,B,C,D,E 暴力,暴力,二分,范德蒙恒等式,树状数组+分块

    题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory ...

  3. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何

    A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

  6. Codeforces 670D1. Magic Powder - 1 暴力

    D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...

  7. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  8. Codeforces 799D. String Game 二分

    D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...

  9. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

随机推荐

  1. gdo图形引擎中的旋转角

    横滚角(Roll) bank.roll  绕y轴 z轴正向为起点逆时针方向:往左为正,往右为负,水平时为0:有效范围:-180度-180度 注:下图是从飞机的尾部-->头部方向观察所得 俯仰角( ...

  2. 莫队算法 2038: [2009国家集训队]小Z的袜子(hose)

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2038 2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 ...

  3. Beego框架使用

    go get github.com/astaxie/beego vim hello.go package main import "github.com/astaxie/beego" ...

  4. 关于ICE

    转自:http://wenda.chinabaike.com/b/38322/2013/1103/614756.html 一.ICE产生的背景 基于信令协议的多媒体传输是一个两段式传输.首先,通过信令 ...

  5. Poisson Image Editing

    说起泊松,可以顺便提及一下泊松同学的老师,拉普拉斯.学图像或是信号的,一定对拉普拉斯算子和拉普拉斯卷积很熟悉.在泊松图像融合出现之前,也有一种叫Laplacian pyramid blending的融 ...

  6. hdu 3001(状压dp, 3进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 由于本题中一个点最多能够访问2次,由此可以联想到3进制; visited[i][j]表示在状态i ...

  7. Streaming data from Oracle using Oracle GoldenGate and Kafka Connect

    This is a guest blog from Robin Moffatt. Robin Moffatt is Head of R&D (Europe) at Rittman Mead, ...

  8. NDK各版本下载

    含r8e,r9d,r10c 其中x86_64代表64位系统 官网上只有最新版下载链接,如果想要下载以前的版本,可打开 https://archive.org/web/ 然后输入 http://deve ...

  9. IconFont和FontAwesome的区别?

    一.[Iconfont] Iconfont支持所有低版本浏览器: Iconfont的图标库更大: Iconfont可以用自己上传的svg,但是要花费大量时间和耐心去设计AI图标: Iconfont的使 ...

  10. 【noip暑假tarjan专题】

    %%%奎老师 A:傻逼缩点...傻逼编译器卡我next... B:就是这道奎老师没讲清楚的题,明明小朋友们都一A嘛,,,明明细节有很多嘛,,,怎么都这么熟练啊. C:本质还是B,换了个马甲而已. D: ...