题意:

  有m(m<=10^4)个金币分给n(n<=1000)个人,第i个人期望得到所有金币的xi/y,现在给分给每个人一些金币ki使得∑|xi/y-ki/m|最小。

Solution:

  首先要算出所有人的期望金币,向下取整.如此一来,所有人期望金币的和s一定小于等于m.这个时候我们需要将剩下的m-s个金币分给m-s个人,对于xi/y-ki/m,将其乘上y*m 得到 xi*m-ki*y,n个人中这个值最大的m-s个人就是我们需要分的人.

#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
struct node {
int p, val;
bool operator < (const node &a) const {
return a.val > val;
}
} tem;
priority_queue<node> ql;
int ans[];
int n, m, y, s;
int main() {
ios::sync_with_stdio ();
cin >> n >> m >> y;
for (int i = , x; i < n; i++) {
cin >> x;
ans[i] = m * x / y;
s += ans[i];
tem.p = i;
tem.val = abs (x * m - ans[i] * y);
ql.push (tem);
}
s = m - s;
while (s--) {
tem = ql.top(); ql.pop();
ans[tem.p]++;
}
for (int i = ; i < n; i++)
cout << ans[i] << ' ';
}

Code

SGU 207.Robbers的更多相关文章

  1. LeetCode - 207. Course Schedule

    207. Course Schedule Problem's Link ---------------------------------------------------------------- ...

  2. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  3. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  4. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  5. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

  6. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

  7. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  8. 树形DP求树的重心 --SGU 134

    令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...

  9. SGU 170 Particles(规律题)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个 ...

随机推荐

  1. 单位分配的IP地址和电脑主机绑定了,我想用设置一个无线路由器,让我的笔记本电脑和手机都能上网?

    单位分配的IP地址和电脑主机绑定了,我想用设置一个无线路由器,让我的笔记本电脑和手机都能上网?     配一个无线路由器就可以实现,将电脑IP配置成自动获取,找条网线一头插路由LAN口(路由器上有标明 ...

  2. 原生javascript难点总结(1)---面向对象分析以及带来的思考

    ------*本文默认读者已有面向对象语言(OOP)的基础*------ 我们都知道在面向对象语言有三个基本特征 :  封装 ,继承 ,多态.而js初学者一般会觉得js同其他类C语言一样,有类似于Cl ...

  3. leetcode First Missing Positive hashset简单应用

    public class Solution { public int firstMissingPositive(int[] A) { HashSet<Integer> hash=new H ...

  4. TCP连接建立的三次握手过程可以携带数据吗?

    前几天实验室的群里扔出了这样一个问题:TCP连接建立的三次握手过程可以携带数据吗?突然发现自己还真不清楚这个问题,平日里用tcpdump或者Wireshark抓包时,从来没留意过第三次握手的ACK包有 ...

  5. zoj 2734 Exchange Cards【dfs+剪枝】

    Exchange Cards Time Limit: 2 Seconds      Memory Limit: 65536 KB As a basketball fan, Mike is also f ...

  6. Android实现弹出输入法时,顶部固定,中间部分上移的效果

    前言 最近做项目时碰到一个问题,在意见反馈里面,提交按钮写到顶部,当用户输入反馈意见或者邮箱手机号时,弹出的输入法会上移整个页面,导致提交按钮显示不了. 很明显,这样的界面是非常不友好的,找了一些资料 ...

  7. C# 光标文件的创建

    base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Resources.MeasuredisTool.cur") ...

  8. C# 字符串常用操作 分类: C# 2014-08-22 15:07 238人阅读 评论(0) 收藏

    string str1 = "C#操作字符串<几种常见方式>如下"; string str2 = "C#操作字符串";     //比较字符串 Co ...

  9. 遍历datatable的几种方法【转载】

    遍历datatable的方法2009-- :02方法一: DataTable dt = dataSet.Tables[]; ; i < dt.Rows.Count ; i++) { string ...

  10. iOS 数据持久化(3):Core Data

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...