Description
Jyy has been thinking of returning to Earth as soon as possible, but his ship's fuel is not enough.
one day he went to the Martians to fuel, this time the Martians promised to jyy with the ship's bottles to change. Jyy
on the ship there are N bottles (1<=n<=1000), after consultation, the Martians as long as the K. Jyy
after handing K bottles to the Martians, the Martians used them to put some fuel into the jyy. All the bottles have no scale, only
The volume is marked at the bottle, and the volume of the I Bottle is VI (vi is an integer and satisfies the 1<=vi<=1000000000).
Martians are stingy, and they are not going to fill all the bottles with fuel. When they get the bottle, they run to the fuel.
the library tinker with a little bit of fuel to get it over with. Jyy, of course, knew they would come to this, so they knew the fire beforehand.
the specific contents of the Star-man Tinker. Martians in the fuel depot will only do the following 3 operations: 1, a bottle filled with fuel;
2. Pour all the fuel in a bottle back into the fuel bank, 3. Pour the fuel from bottle A to bottle B until the bottle B is full.
or bottle A is empty. Losses in the process of fuel dumping can be neglected. The Martians are taking out the fuel, of course, that these operations can
the smallest positive volume obtained.
Jyy knows that for different bottle combinations, Martians may be forced to give different volumes of fuel. Jyy hope to find
to the optimal bottle mix, allowing the Martians to give as much fuel as they could.
Input
Line 1th: 2 integers n,k,
2nd.. N rows: 1 integers per line, and the integer for line i+1 is VI
Output
Only 1 lines, an integer, represents the maximum value of the fuel given by the Martians.
Sample Input3 2
3
4
4Sample Output 4
How to feel the topic so familiar, pour water problem ..., but it seems different
K bottles are loaded with any number of fuel, but that's three rules, we have to convert this problem,
If apart a direct search, it's probably not a problem.
Our simple analysis can be seen, the answer is to choose the volume of the bottle greatest common divisor, do not ask me how to see it ... Because I don't know, either.
The idea is the decomposition factor.
#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#defineMoD 100000using namespacestd;ints[20000000];intans,n,k;intDecomintsum) { for(intI=1; i<=sqrt (sum); + +i)if(! (sum%i)) {s[++ans]=i; if(i!=sum/i) s[++ans]=sum/i; }}intMain () {scanf ("%d%d",&n,&k); for(intI=1; i<=n;++i) {intnum; CIN>>num; decom (num); } sort (S+1, s+ans); intlianxu=1, m=1; for(intI=ans;i>0;--i) {if(s[i+1]==s[i]) Lianxu++; Else { if(lianxu>=k) {printf ("%d", s[i+1]); return 0; } Lianxu=1; } }}
Bzoj 2257: [Jsoi2009] bottles and fuel