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

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

  1. 3 12 1 4
    11 3 16

output

  1. 4

input

  1. 4 3
    4 3 5 6
    11 12 14 20

output

  1. 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个可变化材料,求可做多少饼干。

可暴力,也可直接二分。

小数据直接暴力

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<queue>
  5. #include<algorithm>
  6. #include<cstdio>
  7. #define max(a,b) (a>b?a:b)
  8. #define abs(a) ((a)>0?(a):-(a))
  9. using namespace std;
  10. #define LL long long
  11. #define INF 0x3f3f3f3f
  12. int main()
  13. {
  14. int n,k;
  15. int a[],b[];
  16. while(scanf("%d%d",&n,&k)!=EOF)
  17. {
  18. for(int i=;i<n;i++)scanf("%d",&a[i]);
  19. for(int i=;i<n;i++)scanf("%d",&b[i]);
  20. int aa,flag=;
  21. int num=;
  22. while(k>=) //k>=0,不要k>0
  23. {
  24. for(int i=;i<n;i++){ //找到个数最小点,标记
  25. if(aa>b[i]/a[i]){
  26. flag=i;
  27. aa=b[i]/a[i];
  28. }
  29. }
  30. //下面更新记录
  31. int bb=a[flag]-b[flag]%a[flag];
  32. if(k<bb)break;
  33. else {
  34. k-=bb;
  35. b[flag]+=bb;
  36. aa=b[flag]/a[flag];
  37. }
  38.  
  39. }
  40. cout<<aa<<endl;
  41. }
  42. return ;
  43. }

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

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<queue>
  5. #include<algorithm>
  6. #include<cstdio>
  7. #define max(a,b) (a>b?a:b)
  8. #define abs(a) ((a)>0?(a):-(a))
  9. using namespace std;
  10. #define LL long long
  11. #define INF 0x3f3f3f3f
  12. int n,k;
  13. int a[],b[];
  14. bool ok(LL mid)
  15. {
  16. LL kk=k;
  17. for(int i=;i<n;i++){
  18. if(a[i]*mid>b[i]){
  19. kk-=(a[i]*mid-b[i]);
  20.  
  21. }
  22. if(kk<)return false; //mid太大,跳出; 不能放到上面if里
  23. }
  24. return true; //mid太小,使k有剩余
  25. }
  26. int main()
  27. {
  28. while(~scanf("%d%d",&n,&k))
  29. {
  30. for(int i=;i<n;i++)
  31. scanf("%d",&a[i]);
  32. for(int i=;i<n;i++)
  33. scanf("%d",&b[i]);
  34. LL l=,r=INF;
  35. LL num,mid;
  36. while(l<=r)
  37. {
  38. mid=(l+r)>>;
  39. if(ok(mid)){
  40. l=mid+;
  41. num=mid; //num要在这里赋值
  42. }else {
  43. r=mid-;
  44. }
  45. }
  46. cout<<num<<endl;
  47. }
  48. return ;
  49. }

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. oracle使用dbms_metadata包取得所有对象DDL语句

    当我们想要查看某个表或者是表空间的DDL的时候,可以利用dbms_metadata.get_ddl这个包来查看. dbms_metadata包中的get_ddl函数详细参数 GET_DDL函数返回创建 ...

  2. SQL Server 2014 BI新特性(一)五个关键点带你了解Excel下的Data Explorer

    Data Explorer是即将发布的SQL Server 2014里的一个新特性,借助这个特性讲使企业中的自助式的商业智能变得更加的灵活,从而也降低了商业智能的门槛. 此文是在微软商业智能官方博客里 ...

  3. 允许webservice远程测试

    System.Web节点下添加 <webServices> <protocols> <add name= "HttpPost"/> <ad ...

  4. 在CSDN中添加友情连接

    <a bref='http://www......'>友情连接</a><br/> <a bref='http://www......'>友情连接2< ...

  5. SpringJMS解析3-监听器

    消息监听器容器是一个用于查看JMS目标等待消息到达的特殊bean,一旦消息到达它就可以获取到消息,并通过调用onMessage()方法将消息传递给一个MessageListener实现.Spring中 ...

  6. 去除android手机滚动条

    方法1:::-webkit-scrollbar{display: none;} 方法2:::-webkit-scrollbar{height:0; width:0:}

  7. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  8. cf429B dp递推

    Description Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to loo ...

  9. JQuery学习之遍历

    1.祖先:向上遍历DOM树 **parent():返回被选中元素的直接父元素,该方法只会向上一级对DOM树进行遍历 $(document).ready(function(){ $("span ...

  10. ubuntu 下python版本切换

    1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3