题意:给你一个n,m;其中n一定能被m整除,然后给你n个数

有一种操作   选择n个数中的任意一个,使其+1;

条件:

  Ci 属于[0,m-1]  Ci代表ai模m的余数为i的个数 且都等于n/m;

  (

    比如n=4,m=2;n/m=2;

    a1=0,a2=1,a3=2,a4=3;

    Ci属于[0,1];

    a1%m=0;a2%m=1;a3%m=0;a4%m=1;

    所以C1=C2=n/m=2;

  )

求:最少需要操作几次才能满足以上要求

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <set>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 const int maxn=2e5+5;
 8 ll cnt[maxn],a[maxn],val,res,ans;
 9 set<ll> s;
10 set<ll> ::iterator it;
11 int main()
12 {
13     int n,m;
14     cin>>n>>m;
15     for(int i=0;i<m;cnt[i++]=n/m)
16         s.insert(i);
17     for(int i=1;i<=n;i++)
18     {
19         cin>>a[i];
20         val=a[i]%m;
21         if(val>(*s.rbegin()))res=*s.begin();
22         else res=*s.lower_bound(val);
23         if(!--cnt[res])s.erase(res);
24         ans=ans+(res-val+m)%m;
25         a[i]=a[i]+(res-val+m)%m;
26     }
27     cout<<ans<<endl;
28     for(int i=1;i<=n;i++)
29         cout<<a[i]<<" ";
30     cout<<endl;
31     return 0;
32 }

转载于:https://www.cnblogs.com/Cherry93/p/9930387.html

CodeForces-999D Equalize the Remainders (贪心+神奇的STL)相关推荐

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. Equalize the Remainders(思维)

    Equalize the Remainders You are given an array consisting of n integers a1,a2,-,an, and a positive i ...

  3. 【CodeForces - 999D】Equalize the Remainders(思维,贪心)

    题干: You are given an array consisting of nn integers a1,a2,-,ana1,a2,-,an, and a positive integer mm ...

  4. Codeforces 671E Organizing a Race (贪心、线段树)

    题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...

  5. CodeForces - 1529E Trees of Tranquillity(贪心+线段树)

    题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...

  6. [CodeForces 1603C] Extreme Extension(贪心 + 数论分块优化dp)

    problem CodeForces solution observation1:\text{observation1}:observation1: 对于一个非空子段 [l,r][l,r][l,r], ...

  7. codeforces 416C C. Booking System(贪心)

    题目链接: codeforces 416C 题目大意: 给出n个请求,每个请求包括客人数量和支付金额,再给出m个桌子,包括桌子大小,问如何安排才能最大盈利.给出最大盈利和一个能够最大盈利的方案. 题目 ...

  8. Codeforces 540B School Marks 【贪心构造】

    题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...

  9. CodeForces 508E Arthur and Brackets 贪心

    题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...

最新文章

  1. php 数据库编码,php怎么设置数据库编码方式
  2. linux php jsp网页,Linux上架设支持JSP+PHP的Web服务器
  3. 模型类型与加速潜力的关系
  4. 解决ubuntu中出现:dpkg: error processing package install-info
  5. 区块链第三方支付已登陆菲律宾
  6. 【医疗影像处理】DICOM Rescale Intercept / Rescale Slope
  7. [渝粤教育] 中国地质大学 电力系统保护原理 复习题
  8. api-ms-win-crt-runtime-l1-1-0.dll丢失问题
  9. 3. Spring Boot 从零开始学习
  10. idea全局查找字段
  11. 果然天蝎座的人积分落户最容易...
  12. 如何合并多个PDF文件?这几个小妙招快来码住吧
  13. java获得一年内的所有双休日
  14. 如何在Jupyter Notebook中编写R程序
  15. 量化交易之HFT篇 - 高频做市模型源码(.h文件)
  16. vue 微信登录(前后台详细教程)
  17. 王者荣耀中皮肤和英雄技能java实现
  18. 天空测试显卡软件,显卡烤机软件Furmark 1.20.0.1 | 厘米天空
  19. 微信小程序-申请正式的appid+开通云开发(新建项目之后界面没有云开发按钮)
  20. matlab 基金业绩归因,5分钟搞定基金从业:绝对收益归因和相对收益归因

热门文章

  1. 成交量与股价关系的深度剖析 (一)
  2. 自然语言处理 —— 2.6 word2vec
  3. 转载——Regression Tree 回归树
  4. Collaborative topic modeling(推荐)算法实现中的大数组问题
  5. 斜齿轮传动几何尺寸计算例2:斜齿角度变位-齿轮手册第2版表2.2-9
  6. 查看远程Redis服务器的版本
  7. 数据挖掘之随机事件与随机变量
  8. 贪心法——部分背包问题
  9. 【C语言深入】[002] valotile 关键字:
  10. 将QVTKWidget嵌入到QT窗体,实现点云可视化的基本操作