SGU 207.Robbers

Source: Internet
Author: User

Test instructions

There are M (m<=10^4) gold coins given to n (n<=1000) Individuals, the first I personally expect to get all the gold coins of xi/y, now give each person some gold coins ki makes ∑|xi/y-ki/m| the smallest.

Solution:

The first thing to do is to figure out the desired gold for everyone. So, everyone expects gold and s must be less than or equal to M. This time we need to m-s the rest of the gold coins to m-s individuals, for xi/y-ki/m, the y*m get Xi*m-ki*y, n the most m-s person in this person is the person we need to divide.

#include <iostream>#include<queue>#include<cmath>using namespacestd;structNode {intP, Val; BOOL operator< (ConstNode &a)Const {        returnA.val >Val; }} tem;priority_queue<node>QL;intans[1009];intN, M, y, S;intMain () {Ios::sync_with_stdio (0); CIN>> n >> M >>y;  for(inti =0, X; I < n; i++) {cin>>x; Ans[i]= m * X/y; S+=Ans[i]; TEM.P=i; Tem.val= ABS (x * m-ans[i] *y);    Ql.push (TEM); } s= M-s;  while(s--) {tem=ql.top (); Ql.pop (); ANS[TEM.P]++; }     for(inti =0; I < n; i++) cout<< Ans[i] <<' ';}
Code

SGU 207.Robbers

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.