POJ 1477 ( 贪心 )
来源:互联网 发布:sacdiso mac播放 编辑:程序博客网 时间:2024/05/23 15:39
POJ 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 1017 Packets【贪心】
- POJ 1017 Packets(贪心)
- POJ 1323 简单贪心
- POJ 1065 (贪心)
- POJ 1328 贪心
- POJ 1018 贪心思想
- POJ 1089 贪心算法
- poj 1017 Packets(贪心)
- poj 1017 贪心算法
- poj 1328 贪心
- POJ 3544 贪心
- POJ-1456 Supermarket【贪心】
- poj 1024 贪心、枚举
- Poj 1328 贪心
- POJ 1018 枚举+贪心
- poj 2709 贪心
- Unity + NGUI开发2D游戏的笔记。
- myeclipse8.5
- iphone开发之解决viewWillAppear失效
- int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal ) .
- android手机设置屏幕横竖屏朝向
- POJ 1477 ( 贪心 )
- codeforces-230B-T-primes
- Struts2 XML配置详解
- 初学者快速理解UINavigationController结构
- POJ 1328
- c#汉字转化为拼音
- void main()还是int main()
- C /C++计算程序运行时间
- POj 2823