Bzoj 2257 [Jsoi2009] bottles and fuel

Source: Internet
Author: User

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 isaAndb), 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 maximizedkThe maximum common factor of a bottle.
Consider each number decomposition factor to find the largest and at leastkThe 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.