(HDU) 1326--Box of bricks (bricks)

Source: Internet
Author: User

Title Link: http://vjudge.net/problem/HDU-1326

A pile of bricks to settle, ask at least how many blocks to move. At first, it was thought that at least the number of times to move, a water problem was written as a greedy problem. Mdzz.

Note that the output also has a newline!!

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5#include <algorithm>6#include <string>7#include <cstdlib>8 9 using namespacestd;Ten  One intMain () A { -     intn,num[10010],i,cnt=0; -      while(~SCANF ("%d",&N)) the     { -         intsum=0, ave,ans=0; -         if(n==0) Break; -cnt++; +          for(i=0; i<n;i++) -         { +scanf"%d",&num[i]); Asum+=Num[i]; at         } -ave=sum/(n); -          for(i=0; i<n;i++) -             if(Num[i]<ave) ans+= (ave-num[i]); -printf"Set #%d\nthe Minimum number of moves is%d.\n", Cnt,ans); -printf"\ n"); in     } -     return 0; to}

(HDU) 1326--Box of bricks (bricks)

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.