POJ 1477(贪心)
来源:互联网 发布:linux安装jar命令 编辑:程序博客网 时间:2024/05/11 18:33
题目链接:http://poj.org/problem?id=1477
典型的贪心算法,很水,直接贴代码 PS:需要注意的就是每组数据之后都有一个空行
#include <stdio.h>#include <algorithm>using namespace std;bool cmp(const int a,const int b) { return a>b; }int main(){ int bricks[55]; int n,l=0,i,sum,ave,ans; while(scanf("%d",&n)==1) { if(n==0) break; l++;sum=0;ans=0; for(i=1;i<=n;i++){ scanf("%d",&bricks[i]); sum+=bricks[i]; } sort(bricks+1,bricks+n+1,cmp); ave=sum/n; //printf("ave=%d\n",ave); for(i=1;i<=n;i++) if(bricks[i]>ave) ans+=bricks[i]-ave; printf("Set #%d\n",l); printf("The minimum number of moves is %d.\n\n",ans); } return 0;}
- POJ 1477(贪心)
- POJ 1477 ( 贪心 )
- POJ 1328(贪心)
- POJ 1818(贪心)
- POJ 1065(贪心)
- poj 2054(贪心)
- POJ 1230(贪心)
- poj 3253 (贪心)
- POJ-1694(贪心)
- poj 1328(贪心)
- POJ 1328(贪心)
- POJ 2586(贪心)
- poj 1230(贪心)
- POJ 3617 (贪心)
- POJ 1017(贪心)
- POJ 1456 (贪心)
- POJ 1328(贪心)
- POJ 2437(贪心)
- 类定义中包含自己的对象的问题
- POJ 3694 network 无向图求桥 手写栈版tarjan
- C语言中如何使用宏
- LogCat使用详解
- exit和_exit
- POJ 1477(贪心)
- Using Properties in Objective-C Tutorial 边看边记
- Android 模拟器访问本地机器IP
- C#获取机器码
- c++结构体中包含类对象成员的问题 malloc函数不能调用构造函数 new可以
- 腾讯后台开发面试总结,原创,吐血推荐!!
- 理解JTA与分布事务管理入门
- 输入N个数,从1开始数数到m就把这个数删去,从新从它的下一个从1开始数,直到把所有的都删除。
- 利用C++模板技术支持多种计算策略