D1. Magic Powder - 1
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

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.

Examples
input
3 1
2 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.

题目链接:http://codeforces.com/problemset/problem/670/D1


题意:做一个饼干需要有n种材料,每种材料需要ai克。现在每种材料有bi克。还有k克神奇材料,可以代替那n种材料。1克神奇材料替换1克普通材料。

思路:按num[i]=bi/ai升序。暴力求出num[i]时需要得神奇材料。
 
代码:
for循环直接暴力:
#include<bits/stdc++.h>
using namespace std;
struct ingredient
{
int a,b,num,sign;
} gg[];
int add[];
int cmp(ingredient x,ingredient y)
{
if(x.num!=y.num) return x.num<y.num;
else return x.sign<y.sign;
}
int main()
{
int i,j,n,k;
scanf("%d%d",&n,&k);
for(i=; i<=n; i++)
scanf("%d",&gg[i].a);
for(i=; i<=n; i++)
{
scanf("%d",&gg[i].b);
gg[i].num=gg[i].b/gg[i].a;
gg[i].sign=gg[i].b%gg[i].a;
}
sort(gg+,gg+n+,cmp);
gg[n+].num=gg[n].num+;
gg[n+].sign=;
int sum=,flag=;
add[]=;
for(i=; i<=n; i++)
{
sum+=gg[i].a;
flag+=gg[i].sign;
if(gg[i].num<gg[i+].num)
{
add[i]=add[i-]+sum*(gg[i+].num-gg[i].num)-flag;
if(add[i]>=k)
{
k-=add[i-];
cout<<gg[i].num+(k+flag)/sum<<endl;
break;
}
flag=;
}
else add[i]=add[i-];
}
if(i>n)
{
k-=add[n];
cout<<gg[n+].num+k/sum;
}
return ;
}

每次增加num就进行sort排序:

#include<bits/stdc++.h>
using namespace std;
int a[],b;
struct ingredient
{
int a,b,num;
} gg[];
int cmp(ingredient x,ingredient y)
{
return x.num<y.num;
}
int main()
{
int i,n,k;
scanf("%d%d",&n,&k);
for(i=; i<n; i++)
scanf("%d",&gg[i].a);
for(i=; i<n; i++)
{
scanf("%d",&gg[i].b);
gg[i].num=gg[i].b/gg[i].a;
}
sort(gg,gg+n,cmp);
while(k>)
{
int sign=(gg[].num+)*gg[].a;
if((sign-gg[].b)<=k)
{
k-=(sign-gg[].b);
gg[].b=sign;
gg[].num++;
}
else
{
gg[].b+=k;
k=;
}
sort(gg,gg+n,cmp);
}
cout<<gg[].num<<endl;
return ;
}

Codeforces 670D1. Magic Powder - 1 暴力的更多相关文章

  1. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  2. Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)

    题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...

  3. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  4. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...

  5. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  6. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

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

  8. codeforces 350 div2 D Magic Powder - 2 二分

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

随机推荐

  1. centos6.5 64安装ffmpeg过程支持转码mp3

    百度了几个文章 大致知道了思路 首先yum源安装是木有的,只能编译安装了. 要安装ffmpeg要先安装一个yasm支持汇编优化(FFmpeg需要) 在安装一个lame,支持mp3的转码 那就是需要3步 ...

  2. (3/24)轻松配置 webpack3.x入口、出口配置项

    在上一节中我们只是简单的尝了一下webpack的鲜,对其有了基本的了解,对于上一节当中的打包方式,在实际开发中并不使用,而是通过webpack的配置文件的方式进行设置的,所以该节就在上一节的基础上学一 ...

  3. 微信公众号自动回复 node

    纯属分享记录: app.js var bodyParser = require('body-parser'); require('body-parser-xml')(bodyParser); var ...

  4. [Ora]-1309. OCI is not properly installed on this machine (NOE1/INIT)

    When the Oracle client software has not been properly installed, you will get an exception when tryi ...

  5. MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法

    首先我们建立一张带有逗号分隔的字符串. CREATE TABLE test(id int(6) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id),pname VARCH ...

  6. rssh RSA(非对称密钥)

    rssh ,非对称密钥,分为密钥和公钥 ,密钥在对面机器,需要进入的文件中,公钥是放在本地机器上 import paramiko private_key = paramiko.RSAKey.from_ ...

  7. Mysql 游标使用

    BEGIN #shopsId 商家ID #accountDay 10位日期 -- 定义一个或者多个 变量来接收 游标查询的列值 DECLARE receiptContentId INT; -- 遍历数 ...

  8. 基于OpenGL编写一个简易的2D渲染框架-07 鼠标事件和键盘事件

    这次为程序添加鼠标事件和键盘事件 当检测到鼠标事件和键盘事件的信息时,捕获其信息并将信息传送到需要信息的对象处理.为此,需要一个可以分派信息的对象,这个对象能够正确的把信息交到正确的对象. 实现思路: ...

  9. 【Web缓存机制系列】2 – Web浏览器的缓存机制

    Web缓存的工作原理 所有的缓存都是基于一套规则来帮助他们决定什么时候使用缓存中的副本提供服务(假设有副本可用的情况下,未被销毁回收或者未被删除修改).这些规则有的在协议中有定义(如HTTP协议1.0 ...

  10. ASP.NET MVC+JQueryEasyUI1.4+ADO.NET Demo

    1.JQueryEasyUI使用 JQuery EasyUI中文官网:http://www.jeasyui.net/ JQuery EasyUI中文官网下载地址:http://www.jeasyui. ...