Today, open a blog,,, excited, for the first time AH
Well, let's FA shui the first question.
D1. Magic Powder-1
This problem are given in and versions that differ only by constraints. If you can solve this problem in large constraints and 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 on the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n Ingredients, and for each ingredient she knows the value a i -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 is 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 are able to bake using the ingredients that she Has and the magic powder.
Input
The first line of the input contains the 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 a 1, A 2, ..., a n ( 1≤ a i ≤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 would be a able to bake using the ingredients that she have and the mag IC Powder.
Examplesinput
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's profitably for Apollinaria to make the existing 1 gram of hers magic powder to ingredient wit H The index 2, then Apollinaria'll is 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'll is able to bake 3 cookies. The remaining 1 gram of the magic powder can be left and because it can ' t be used to increase the answer.
1, Codeforces 670d12, Link: http://codeforces.com/problemset/problem/670/D13, summary: Test instructions, give n kinds of materials to make a biscuit, N of the number of existing materials, K can change materials, Ask how many biscuits to make. Can be violent, can also direct two points. Small Data Direct violence
#include <iostream>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>#defineMax (A, B) (A>B?A:B)#defineABS (a) ((a) >0? ( A):-(a))using namespacestd;#defineLL Long Long#defineINF 0x3f3f3f3fintMain () {intn,k;inta[ the],b[ the]; while(SCANF ("%d%d", &n,&k)! =EOF) { for(intI=0; i<n;i++) scanf ("%d",&a[i]); for(intI=0; i<n;i++) scanf ("%d",&b[i]);intaa,flag=0;intnum=0; while(k>=0)//k>=0, don't k>0.{ for(intI=0; i<n;i++) {//find the minimum number of points, Markif(aa>b[i]/A[i]) {Flag=I;aa=b[i]/a[i];}}//update the record belowintbb=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 0;}
Big Data two points
Reference to the http://blog.csdn.net/qiuxueming_csdn/article/details/51471935
#include <iostream>#include<cstring>#include<cmath>#include<queue>#include<algorithm>#include<cstdio>#defineMax (A, B) (A>B?A:B)#defineABS (a) ((a) >0? ( A):-(a))using namespacestd;#defineLL Long Long#defineINF 0x3f3f3f3fintn,k;inta[1000000],b[1000000];BOOLOK (ll mid) {ll KK=K; for(intI=0; i<n;i++){if(a[i]*mid>B[i]) {KK-= (a[i]*mid-b[i]);}if(kk<0)return false;//mid is too big to jump out;}return true;//mid is too small, so K has surplus}intMain () { while(~SCANF ("%d%d",&n,&k)) { for(intI=0; i<n;i++) scanf ("%d",&a[i]); for(intI=0; i<n;i++) scanf ("%d",&B[i]); LL L=0, r=INF; LL Num,mid; while(l<=R) {Mid= (l+r) >>1;if(OK (mid)) {L=mid+1; Num=mid;//num is going to assign a value here .}Else{R=mid-1;}} cout<<num<<Endl;}return 0;}
Codeforces 670d1 violence or dichotomy