Bzoj 2257: [Jsoi2009] bottles and fuel

Source: Internet
Author: User

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 Output4

HINT

By choosing the 2nd bottle and the first bottle, the Martians were forced to give 4 volumes.

Solution: This topic, first of all to know a theorem, bezout theorem: a*x+b*y+c*d=hh, satisfies the a,b,c are all integers, so that the equation x,y,d solutions are integers the minimum HH value is gcd (a,b,c).  Of course, the situation can be generalized to n items.  Then, this topic is converted to the number of k from the n number, Gaga minus, maximize the minimum value of Gaga minus, this can think about. Then we for each number, to find each number factor, if it contains the number of this factor >k, then can become the answer, then I will take the largest of these numbers can be. Code:
#include <cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<iostream>#include<map>#include<vector>using namespaceStd;map<int,int>Mp;vector<int>Yin;intn,k;intMain () {CIN>>n>>K;  for(intI=1; i<=n;i++){        intX;SCANF ("%d",&x);  for(intj=1; j<=sqrt (x); J + +){            if(x%j==0){                if(mp[j]==0) Yin.push_back (j); MP[J]++; if(j*j==x)Continue; if(mp[x/j]==0) Yin.push_back (x/j); Mp[x/j]++;    }}} sort (Yin.begin (), Yin.end ());  for(intI=yin.size ()-1; i>=0; i--){        if(mp[yin[i]]>=k) {printf ("%d", Yin[i]); return 0; }    }    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.