码迷,mamicode.com
首页 > 其他好文 > 详细

(HDU)1326 -- Box of Bricks (砖块)

时间:2016-12-06 03:00:38      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:math   string   blog   main   code   span   hdu   ble   include   

题目链接:http://vjudge.net/problem/HDU-1326

一堆砖要摆平,问最少移动多少块。刚开始认为是最少要移动多少次,一个水题被写成了贪心题。mdzz。

注意输出还有一个换行!!

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 
11 int main()
12 {
13     int n,num[10010],i,cnt=0;
14     while(~scanf("%d",&n))
15     {
16         int sum=0,ave,ans=0;
17         if(n==0) break;
18         cnt++;
19         for(i=0;i<n;i++)
20         {
21             scanf("%d",&num[i]);
22             sum+=num[i];
23         }
24         ave=sum/(n);
25         for(i=0;i<n;i++)
26             if(num[i]<ave) ans+=(ave-num[i]);
27         printf("Set #%d\nThe minimum number of moves is %d.\n",cnt,ans);
28         printf("\n");
29     }
30     return 0;
31 }

 

(HDU)1326 -- Box of Bricks (砖块)

标签:math   string   blog   main   code   span   hdu   ble   include   

原文地址:http://www.cnblogs.com/ACDoge/p/6135743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!