ACdream 1224(贪心处理)
来源:互联网 发布:ubuntu 硬盘大小 编辑:程序博客网 时间:2024/05/29 08:33
题目链接:http://acdream.info/problem?pid=1224
Robbers
Problem Description
N robbers have robbed the bank. As the result of their crime they chanced to get M golden coins. Before the robbery the band has made an agreement that after the robbery i-th gangster would get Xi/Y of all money gained. However, it turned out that M may be not divisible by Y.
The problem which now should be solved by robbers is what to do with the coins. They would like to share them fairly. Let us suppose that i-th robber would get Ki coins. In this case unfairness of this fact is |Xi/Y - Ki/M|. The total unfairness is the sum of all particular unfairnesses. Your task as the leader of the gang is to spread money among robbers in such a way that the total unfairness is minimized.
Input
Output
Sample Input
3 10 41 1 2
Sample Output
2 3 5
Source
接下来贪心排序即可
#include <iostream>#include <string.h>#include <string>#include <cstdio>#include <cmath>#include <algorithm>const int N=1100;using namespace std;struct node{ int id; double inf; int p;}a[N];bool cmp(node a,node b){ return a.inf<b.inf;}int b[N],q[N];int cnt[N];int main(){ int n,m,y; while(scanf("%d%d%d",&n,&m,&y)!=EOF) { int sum=0,left=0; for(int i=1;i<=n;i++) { int temp; scanf("%d",&temp); q[i]=temp; b[i]=temp*m/y; sum+=b[i]; } left=m-sum; for(int i=1;i<=n;i++) { a[i].id=i; a[i].inf=abs((b[i]+1.0)/m-(q[i]*1.0)/y)-abs((b[i]*1.0)/m-(q[i]*1.0)/y); a[i].p=b[i]; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { cnt[a[i].id]=a[i].p; } for(int i=1;i<=left;i++) { cnt[a[i].id]++; } for(int i=1;i<=n;i++) if(i==1) printf("%d",cnt[i]); else printf(" %d",cnt[i]); printf("\n"); } return 0;}
- ACdream 1224(贪心处理)
- acdream 1224(贪心)
- ACdream 1224 Robbers (贪心)
- acdream 1073(贪心)
- acdream 1714(贪心)
- acdream 1715(贪心)
- acdream 1717(贪心)
- acdream 1716(贪心)
- acdream 1212(贪心)
- ACdream发电站(贪心)
- ACDREAM 03D ACdream王国的花店(贪心专场)
- ACDREAM 03E ACdream王国的士兵(贪心专场)
- ACDREAM 03G ACdream的高速公路(贪心专场)
- acdream 1015Double Kings 树形结构 贪心
- ACDREAM 03C Robbers(贪心专场)
- ACdream 1015 Double Kings【贪心*2】
- ACdream 1224 Robbers
- ACdream
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
- NSSortDescriptor(数组排序)
- 判断两链表是否相交
- oracle 8.1.7下载
- android面试1
- ACdream 1224(贪心处理)
- jquery 实现iframe高度自适应
- POJ3352-Road Construction(边连通分量)
- acdream 1220 哈夫曼树
- 将WebCollector导入普通项目
- 好用的模板(不断增补中)
- 偶数
- 体系结构课程报告
- KMP 专场 POJ2752