HDU 1326 Box of bricks (water ~ average height for minimum moving bricks)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1326

Main topic:

To the n wall, each wall of different heights, the minimum number of moving block to make the wall of the same height.

Problem Solving Ideas:

Find the average wall height (that is, the height of the last wall), traverse all the walls, if less than the average wall, then the average wall minus the height is the height to move, statistics all the need to "fill" the height. Note the output.

AC Code:

1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5     intn,k=1;6      while(SCANF ("%d", &n)!=eof&&N)7     {8         intna[n+1],cut=0;9          for(intI=0; i<n; i++)Tenscanf"%d", &na[i]), cut+=Na[i]; One         intavg=cut/N; Acut=0; -          for(intI=0; i<n; i++) -             if(na[i]<avg) thecut+= (avg-na[i]); -printf"Set #%d\n", k++); -printf"The minimum number of moves is%d.\n\n", cut); -     } +     return 0; -}

HDU 1326 Box of bricks (water ~ average height for minimum moving bricks)

Related Article

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.