日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 670D1 Magic Powder - 1

發布時間:2024/1/1 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 670D1 Magic Powder - 1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?題目鏈接:http://codeforces.com/problemset/problem/670/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 needsn ingredients, and for each ingredient she knows the valueai?— 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 thei-th ingredient. Also she hask grams of a magic powder. Each gram of magic powder can be turned to exactly1 gram of any of then 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 thei-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 thei-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 index1 and1 gram of magic powder to ingredient with the index3. Then Apollinaria will be able to bake3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

題意:首先給出有n種原材料和k個魔法棒(一個魔法棒可變成任意原材料中任意一種中的的一份),接下來給出加工一件物品所需每種原材料的量,下面給出現在每種原材料所有量,求做多可以做出多少件物品

思路:數據要求不大,直接進行暴力求解

代碼:

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <cstring> #include <stack> using namespace std;int n,k; int a[1005]; int b[1005]; struct point {int a;int b;int c; } p[1005];int main() {cin >> n >> k;int maxn = 0xffffff;for(int i = 0; i < n; i++) {cin >> a[i];}for(int i = 0; i < n; i++) {cin >> b[i];p[i].a = b[i]/a[i];//獲得這一樣東西最大能夠滿足多少個p[i].b = b[i]%a[i];//獲得剩余量p[i].c = a[i]-p[i].b;//獲得補多少maxn = min(maxn,p[i].a);}while(true) {int i;for(i = 0; i < n; i++) {if(p[i].a == maxn) {//說明只有這種物品數量不夠,需要補充if(k < p[i].c) {//魔法棒的數量不足以填充break;} else {k -= p[i].c;//魔法棒數量減少多少p[i].c = a[i];//說明下一次需要補的量p[i].a = maxn+1;//補一次這種的個數就加一保證下一次仍然要繼續補}}}if(i == n) {maxn++;} else {break;}}cout << maxn << endl;return 0; }

D2數據量變大以后直接對答案進行二分

AC代碼:

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <cstring> #include <stack> using namespace std;int n,k; int a[100005]; int b[100005];bool ok(long long x) {long long s = k;for(int i = 0; i < n; i++) {if(x*a[i] >= b[i]) {s -= (x*a[i]-b[i]);}if(s < 0) {return false;}}return true; } int main() {cin >> n >> k;for(int i = 0; i < n; i++) {cin >> a[i];}for(int j = 0; j < n; j++) {cin >> b[j];}if(n == 1) {cout << (b[0]+k)/a[0] << endl;} else {int sum =0;long long l = 0,r = 0xffffffff;long long mid;while(l <= r) {mid=(l+r)>>1;if(ok(mid)) {l = mid+1;sum = mid;} else {r = mid-1;}}cout << sum << endl;}return 0; }

總結

以上是生活随笔為你收集整理的codeforces 670D1 Magic Powder - 1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。