Title: http://www.lydsy.com/JudgeOnline/problem.php?id=2257
Test instructions: Given the capacity of N bottles, select the K to maximize the minimum volume that can be expressed between k bottles without a measure. k ≤ ≤ 1000 Capacity ≤9 。
Exercises
Consider two bottles (capacity isa
Andb
), the volume that can be represented by falling to each other is a value generated from two bottle capacityax+by
, while(a,b)|ax+by
, so the smallest volume is(a,b)
, extended to K bottles, the title is maximizedk
The maximum common factor of a bottle.
Consider each number decomposition factor to find the largest and at leastk
The second factor can be.
The time complexity of the map is not considered O(N max{V} ? ? ? ? ? ? ? √ ) 。
Code:
#include <map>#include <cstdio>#include <algorithm>using namespace STD; map<int, int>CntintN, K, x, I;intMain () {scanf("%d%d", &n, &k); while(n--) {scanf("%d", &x); for(i =1; I * i < x; ++i)if(x% i = =0) ++cnt[i], ++cnt[x/i];if(I * i = = x) ++cnt[i]; } map<int, int>:: Iterator it = Cnt.end (), JT = Cnt.begin (); for(--it,--JT; it! = JT;--it)if(It-second >= K) {printf("%d\n", it-first); Break; }return 0;}
Bzoj 2257 [Jsoi2009] bottles and fuel