B. Two Cakes(思维+暴力)

It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.

Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:

  1. Each piece of each cake is put on some plate;
  2. Each plate contains at least one piece of cake;
  3. No plate contains pieces of both cakes.

To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.

Help Ivan to calculate this number x!

Input

The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.

Output

Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.

Examples
Input
Copy
5 2 3
Output
1
Input
Copy
4 7 10
Output
3
Note

In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.

In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.

题意:一共n个盘子,a块第一种蛋糕,b块第二种蛋糕,将蛋糕全部放在盘子里,满足

1.所有蛋糕在盘中   2.所有盘子有蛋糕   3.同一个盘子里不能有同一种蛋糕

求: 盘子里蛋糕数量的最小值的最大值

思路:要想蛋糕的最小值最大,蛋糕应该均分,枚举放第一种蛋糕的盘子数量

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int maxt=0;
	if(a+b==n) maxt=1;
	else{
		for(int i=1;i<n;i++){
			int tem=a/i;
			int temp=b/(n-i);
			maxt=max(maxt,min(tem,temp));
		}
	}
	printf("%d\n",maxt);
	return 0;
} 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main{ public static void main(String[] args) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n; double need; double sum=0; String s[]=in.readLine().split(" "); n=Integer.parseInt(s[0]); need=Double.parseDouble(s[1]); String amount[]=in.readLine().split(" "); String price[]=in.readLine().split(" "); ArrayList<Mooncake> cakes=new ArrayList<Mooncake>(); for(int i=0;i<n;i++){ Mooncake cake=new Mooncake(); cake.setAmount(Double.parseDouble(amount[i])); cake.setSales(Double.parseDouble(price[i])); cake.setValues(Double.parseDouble(price[i])/Double.parseDouble(amount[i])); cakes.add(cake); } Collections.sort(cakes); for(Mooncake c: cakes){ if(need>=c.amount){ need=need-c.amount; sum+=c.amount*c.values; } else{ sum+=need*c.values; need=0; } if(need==0){ break; } } System.out.printf("%.2f",sum); } static class Mooncake implements Comparable<Mooncake>{ double amount; double sales; double values; public double getAmount() { return amount; } public void setAmount(double amount) { this.amount = amount; } public double getSales() { return sales; } public void setSales(double sales) { this.sales = sales; } public double getValues() { return values; } public void setValues(double values) { this.values = values; } @Override public int compareTo(Mooncake arg0) { // TODO Auto-generated method stub return this.values>arg0.values?-1:1; } } }转c++
最新发布
05-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值