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;
)
求:最少需要操作几次才能满足以上要求
代码如下:
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
ll cnt[maxn],a[maxn],val,res,ans;
set<ll> s;
set<ll> ::iterator it;
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<m;cnt[i++]=n/m)
s.insert(i);
for(int i=;i<=n;i++)
{
cin>>a[i];
val=a[i]%m;
if(val>(*s.rbegin()))res=*s.begin();
else res=*s.lower_bound(val);
if(!--cnt[res])s.erase(res);
ans=ans+(res-val+m)%m;
a[i]=a[i]+(res-val+m)%m;
}
cout<<ans<<endl;
for(int i=;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
return ;
}
CodeForces-999D Equalize the Remainders (贪心+神奇的STL)的更多相关文章
- Codeforces 999D Equalize the Remainders (set使用)
题目连接:Equalize the Remainders 题意:n个数字,对m取余有m种情况,使得每种情况的个数都为n/m个(保证n%m=0),最少需要操作多少次? 每次操作可以把某个数字+1.输出最 ...
- CodeForces - 999D Equalize the Remainders (模拟+set)
You are given an array consisting of nn integers a1,a2,…,ana1,a2,…,an , and a positive integer mm . ...
- D. Equalize the Remainders set的使用+思维
D. Equalize the Remainders set的学习::https://blog.csdn.net/byn12345/article/details/79523516 注意set的end ...
- D. Equalize the Remainders (set的基本操作)
D. Equalize the Remainders time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- D. Equalize the Remainders 解析(思維)
Codeforce 999 D. Equalize the Remainders 解析(思維) 今天我們來看看CF999D 題目連結 題目 略,請直接看原題 前言 感覺要搞個類似\(stack\)的東 ...
- Codeforces Round #550 (Div. 3) D. Equalize Them All (贪心,模拟)
题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作 ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
随机推荐
- poj 2506 Tiling(大数+规律)
poj2506Tiling 此题规律:A[0]=1;A[1]=1;A[2]=3;--A[n]=A[n-1]+2*A[n-2];用大数来写,AC代码: #include<stdio.h> # ...
- HDU5195 线段树+拓扑
DZY Loves Topological Sorting Problem Description A topological sort or topological ordering of a di ...
- ambarella H2 添加文件到ext4文件系统
方法1: ambarella/rootfs目录下有skeleton(骨架)目录,此目录下就是文件系统的各个目录, [root@jz4775dev]# ls skeleton/ bin debug de ...
- 使用ALSA编写自己的音频程序【转】
本文转载自:http://blog.csdn.net/beyondioi/article/details/6994548 Alsa是Linux高级音频接口.面对众多的音频设备,Alsa为Linux音频 ...
- python统计ES存储空间占用的代码
import os from os.path import join, getsize def get_dir_size(dir, suffix_filter=None): size = 0L if ...
- Socket之shutdown()用法
通常来说,socket是双向的,即数据是双向通信的.但有些时候,你会想在socket上实现单向的socket,即数据往一个方向传输. 单向的socket便称为半开放Socket.要实现半开放式,需要用 ...
- nyoj--990--蚂蚁感冒(模拟)(思维题)
蚂蚁感冒 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 长100厘米的细长直杆子上有n只蚂蚁.它们的头有的朝左,有的朝右. 每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/ ...
- ubuntu 12.10 禁用触摸板
1. 打开终端,输入 sudo rmmod psmouse 禁用触摸板,输入 sudo modprobe psmouse 恢复触摸板 2.syndaemon -i 10 -d >/dev/nul ...
- android apk 防止反编译技术第二篇-运行时修改Dalvik指令
上一篇我们讲了apk防止反编译技术中的加壳技术,如果有不明白的可以查看我的上一篇博客http://my.oschina.net/u/2323218/blog/393372.接下来我们将介绍另一种防止a ...
- hdu3555Bomb(数位dp)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submi ...