f505: 10603 - Fill
Tags : BFS CPE UVA 倒水問題
Accepted rate : 5人/6人 ( 83% ) [非即時]
評分方式:
Tolerant

最近更新 : 2020-12-18 16:08

Content

給容量分別為a,b,c的三杯水,倒法是一杯水到另一杯水倒到自己空或是別人滿為止,一開始a,b是空的c是滿的問是否能得到d的水如果不能則輸出d'(小於d最大的容量)

There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater than 200). The first and the second jug are initially empty, while the third is completely filled with water. It is allowed to pour water from one jug into another until either the first one is empty or the second one is full. This operation can be performed zero, one or more times.
You are to write a program that computes the least total amount of water that needs to be poured;so that at least one of the jugs contains exactly d liters of water (d is a positive integer not greater than 200). If it is not possible to measure d liters this way your program should find a smaller amount of water d' < d which is closest to d and for which d' liters could be produced. When d' is found, your program should compute the least total amount of poured water needed to produce d' liters in at least one of the jugs.

Input

第一行有個T代表測資數
接下來T行分別有a,b,c,d(0<a,b,c,d<200)

The first line of input contains the number of test cases. In the next T lines, T test cases follow. Each test case is given in one line of input containing four space separated integers — a, b, c and d.

Output

輸出最少要到多少的水和d或d'

The output consists of two integers separated by a single space. The first integer equals the least total amount (the sum of all waters you pour from one jug to another) of poured water. The second integer equals d, if d liters of water could be produced by such transformations, or equals the closest smaller value d' that your program has found.

Sample Input #1
2
2 3 4 2
96 97 199 62
Sample Output #1
2 2
9859 62
測資資訊:
記憶體限制: 512 MB
公開 測資點#0 (10%): 0.1s , <1M
公開 測資點#1 (10%): 0.1s , <1M
公開 測資點#2 (10%): 0.1s , <1M
公開 測資點#3 (10%): 0.1s , <1M
公開 測資點#4 (10%): 0.1s , <1M
公開 測資點#5 (10%): 0.1s , <1M
公開 測資點#6 (10%): 0.1s , <1M
公開 測資點#7 (10%): 0.1s , <1M
公開 測資點#8 (10%): 0.1s , <1M
公開 測資點#9 (10%): 0.1s , <1M
Hint :

2019 3月CPE第七題

Tags:
BFS CPE UVA 倒水問題
出處:
UVA10603 [管理者:
DE45A (一葉之秋)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」