CodeForces-999D Equalize the Remainders (贪心+神奇的STL)
题意:给你一个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)相关推荐
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Equalize the Remainders(思维)
Equalize the Remainders You are given an array consisting of n integers a1,a2,-,an, and a positive i ...
- 【CodeForces - 999D】Equalize the Remainders(思维,贪心)
题干: You are given an array consisting of nn integers a1,a2,-,ana1,a2,-,an, and a positive integer mm ...
- Codeforces 671E Organizing a Race (贪心、线段树)
题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...
- CodeForces - 1529E Trees of Tranquillity(贪心+线段树)
题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...
- [CodeForces 1603C] Extreme Extension(贪心 + 数论分块优化dp)
problem CodeForces solution observation1:\text{observation1}:observation1: 对于一个非空子段 [l,r][l,r][l,r], ...
- codeforces 416C C. Booking System(贪心)
题目链接: codeforces 416C 题目大意: 给出n个请求,每个请求包括客人数量和支付金额,再给出m个桌子,包括桌子大小,问如何安排才能最大盈利.给出最大盈利和一个能够最大盈利的方案. 题目 ...
- Codeforces 540B School Marks 【贪心构造】
题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...
- CodeForces 508E Arthur and Brackets 贪心
题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...
最新文章
- php 数据库编码,php怎么设置数据库编码方式
- linux php jsp网页,Linux上架设支持JSP+PHP的Web服务器
- 模型类型与加速潜力的关系
- 解决ubuntu中出现:dpkg: error processing package install-info
- 区块链第三方支付已登陆菲律宾
- 【医疗影像处理】DICOM Rescale Intercept / Rescale Slope
- [渝粤教育] 中国地质大学 电力系统保护原理 复习题
- api-ms-win-crt-runtime-l1-1-0.dll丢失问题
- 3. Spring Boot 从零开始学习
- idea全局查找字段
- 果然天蝎座的人积分落户最容易...
- 如何合并多个PDF文件?这几个小妙招快来码住吧
- java获得一年内的所有双休日
- 如何在Jupyter Notebook中编写R程序
- 量化交易之HFT篇 - 高频做市模型源码(.h文件)
- vue 微信登录(前后台详细教程)
- 王者荣耀中皮肤和英雄技能java实现
- 天空测试显卡软件,显卡烤机软件Furmark 1.20.0.1 | 厘米天空
- 微信小程序-申请正式的appid+开通云开发(新建项目之后界面没有云开发按钮)
- matlab 基金业绩归因,5分钟搞定基金从业:绝对收益归因和相对收益归因