当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4186:Numbers Game

题目描述
The objective of the numbers game is to use the basic arithmetic operations (+, -, * and /) and a number of given integers (4 to 7 integers) to get as close as possible to a given target integer. Each of the operations can be used multiple times, but each of the integers can be used at-most once. A player wins if he/she manages to calculate the closest possible value to the target integer. For example, the closest possible value to a target of 20 using the integers {2,3,5} can be achieved by the expression (2+5) * 3. Your task is to write a program to calculate the answer for each game. Note that “/” stands for integer division (examples are: 5/4 equals 1, 8/9 equals 0.)
输入解释
The input consists of many games. The description for each game is given on two lines. The first line contains two integers T and N, separated by a single space, that represent the target integer and the number of given integers. -700,000 <= T <= 700,000 and 4 <= N <= 7. The second line contains N integers separated by single spaces. All integers have values between -1,000,000 and 1,000,000 inclusive. Two zeros on a line by themselves, separated by a single space, terminate the input.
输出解释
For each game, the output consists of a single line that contains the closest possible integer to the target. Any answer with the smallest distance to the target is correct.
输入样例
30 5
1 2 3 4 5
10000 5
11 2 3 7 5
0 0
输出样例
30
2310
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4186

最后修改于 2020-10-25T23:11:04+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/3000MS(Java/Others) 32768/32768K(Java/Others)