Codeforces 151A Soft Drinking 軟性飲料

題目說明

難易度 : 800

英文原文如下

This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called “Take-It-Light” to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.

To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?

中文翻譯

這個冬天在Nvodsk非常寒冷! 一群 n 個朋友決定買 k 瓶一種叫做“Take-It-Light”的軟性飲料來稍微取暖。每瓶飲料含有l 毫升。此外,他們還買了 c 個檸檬,並將每個萊姆切成 d 片。然後他們找到了 p 克鹽。

為了乾杯,每個朋友需要 nl 毫升的飲料,一片萊姆和 np 克的鹽。朋友們想要盡可能多地乾杯,前提是他們都喝相同的量。每個朋友可以乾幾次杯?

輸入

The first and only line contains positive integers nklcdpnlnp, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.

第一與唯一的一行包含了正整數們 nklcdpnlnp,不會超過 1000以及不會低於1。每個數字用空格間隔開。

輸出

Print a single integer — the number of toasts each friend can make.

印出一個整數 — 每一位朋友可以進行乾杯的次數。

範例

輸入3 4 5 10 8 100 3 1
輸出2
輸入5 100 10 1 19 90 4 3
輸出3
輸入10 1000 1000 25 23 1 50 1
輸出0

筆記

A comment to the first sample:

Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is min(6, 80, 100) / 3 = 2.

對於第一個範例:

所有的朋友共有 4*5=20 毫升的飲料,可以進行 20/3 = 6次乾杯。萊姆足夠進行 10*8 = 80次乾杯,鹽巴則足夠進行 100/1 = 100乾杯。然後,這個群體有3個朋友,所以答案是 min(6, 80, 100) / 3 = 2


解題思路

這一題難的就只是在於參數有夠多…

C#解決方案

方案1

string[] arr = Console.ReadLine().Split(" ");
int n = int.Parse(arr[0]);  //朋友的數量
int k = int.Parse(arr[1]);  //軟性飲料的瓶數
int l = int.Parse(arr[2]);  //每瓶飲料的毫升數
int c = int.Parse(arr[3]);  //萊姆的數量
int d = int.Parse(arr[4]);  //每一顆萊姆可以切成幾片
int p = int.Parse(arr[5]);  //鹽巴的克數
int nl = int.Parse(arr[6]); //一次乾杯所需的飲料毫升數
int np = int.Parse(arr[7]); //一次乾杯所需的鹽巴克數

int minNum = Math.Min(Math.Min(k*l/nl,c*d),p/np);   //總共可以得出的乾杯次數
Console.WriteLine(minNum/n);

總而言之,乾一次杯, 每個朋友需要 nl 毫升的飲料,一片萊姆和 np 克的鹽

故取得各項資源各自可以乾幾次杯再取得最小數(min),就是實際可以做出的乾杯次數~


結論

🧡如果文章有幫上你的忙,那是我的榮幸

🧡收藏文章或幫我點個廣告,那都是對我的支持

✅如有任何疑問,歡迎透過留言或messenger讓我知道 !

題目連結 : Problem – 151A – Codeforces

一些其他的Codeforces文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *