【python】COCI ‘08 Contest 2 #3 Perket

COCI '08 Contest 2 #3 Perket
Vote on problem points
Voting statistics
阅读题解
分数:7
时间限制:0.6s
内存限制:32M
题目类型
“Perket” is a widely known and delicious meal. For perket to be what it is, cooks must carefully choose the ingredients to get the fullest taste possible while keeping the meal traditional.

You have ingredients at your disposal. For each we know its sourness and bitterness . When using multiple ingredients, the total sourness is the product of sourness amounts of all ingredients, while the total bitterness is the sum of bitterness amounts of all ingredients.

As everyone knows, perket is supposed to be neither sour nor bitter; we want to choose the ingredients so that the absolute difference between sourness and bitterness is the smallest.

Also, it is necessary to use at least one ingredient; you can’t serve water as the main course.

Input Specification
The first line contains the integer , the number of ingredients at our disposal. Each of the next lines contains two integers separated by a space, the sourness and bitterness of each ingredient.

The input data will be such that, if we make a meal with all ingredients, both the sourness and bitterness will be less than .

Output Specification
Output the smallest possible difference between sourness and bitterness.

Sample Input 1
1
3 10
Sample Output 1
7
Sample Input 2
2
3 8
5 8
Sample Output 2
1
Sample Input 3
4
1 7
2 6
3 8
4 9
Sample Output 3
1
In the third example, we choose the last three ingredients. The total sourness is then and bitterness is . The difference is .

翻译:
Perket 是一种流行的美食。为了做好 Perket,厨师必须谨慎选择食材,以在保持传统风味的同时尽可能获得最全面的味道。你有 nn 种可支配的配料。对于每一种配料,我们知道它们各自的酸度 ss 和苦度 bb。当我们添加配料时,总的酸度为每一种配料的酸度总乘积;总的苦度为每一种配料的苦度的总和。
众所周知,美食应该做到口感适中,所以我们希望选取配料,以使得酸度和苦度的绝对差最小。
另外,我们必须添加至少一种配料,因为没有任何食物以水为配料的。
输入:
第一行包含整数N,即我们可以使用的成分数量。接下来的每一行都包含两个用空格分隔的整数,即每种成分的酸苦程度。
输入数据将是这样的,如果我们用所有的食材做一顿饭,酸酸和苦味都将小于1000000000。
输出:
输出酸味和苦味之间的最小差异。
在这里插入图片描述

import sys
from itertools import combinations
input = sys.stdin.readline
ans = float('inf')
sour = []
bitter = []
N = int(input())
for i in range(N):
	s, b = map(int, input().split())
	sour.append(s)
	bitter.append(b)
temp = [x for x in range(N)]
for i in range(1, N+1):
	for c in combinations(temp, i):
		sness = 1
		bness = 0
		for pos in c:
			sness *= sour[pos]
			bness += bitter[pos]
		ans = min(ans, abs(sness - bness))
print (ans)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白驹_过隙

听说打赏的都进了福布斯排行榜

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值