链接:Problem - 1551B2 - Codeforces

题意:有m个颜色,要求每种颜色内的数字各不相同,问,颜色的最大长度多少。

题解:  判断每个数字的个数,如果大于m,那么最大长度就加一,不大于就都加到一起,看看最后能凑几对。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=2e5+1;
ll a[N],p[N];
ll vis[N];
vector<ll> r,sum[N];
ll ans[N];
bool cmp(ll a,ll b){
return sum[a]<sum[b];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll t;cin>>t;
while(t--){
ll n,m;cin>>n>>m;
for(ll i=0;i<=n;i++){
sum[i].clear();ans[i]=0;
}
r.clear();
for(ll i=1;i<=n;i++){
cin>>a[i];sum[a[i]].push_back(i);
}
for(ll i=1;i<=n;i++){
if(!sum[i].size()) continue;
if(sum[i].size()>=m){
for(ll j=0;j<m;j++)
ans[sum[i][j]]=j+1;
}
else
for(ll j=0;j<sum[i].size();j++){
r.push_back(sum[i][j]);
}
}
if(r.size()>=m){
for(ll i=0;i<r.size()&&r.size()-i>=m;i+=m){
for(ll j=0;j<m;j++) ans[r[i+j]]=j+1;
}
}
for(ll i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
}

B2. Wonderful Coloring - 2的更多相关文章

  1. 推荐一个iOS关于颜色的库-Wonderful

    Wonderful 这个库主要是与UIColor息息相连的,其中一共包含四个子文件,UIColor+Wonderful,UIColor+Separate,SXColorGradientView,SXM ...

  2. Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)

    题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...

  3. CF149D. Coloring Brackets[区间DP !]

    题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...

  4. codeforce ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver! 线段树

    B2. Shave Beaver!   The Smart Beaver has recently designed and built an innovative nanotechnologic a ...

  5. Codeforces Round #369 (Div. 2) C. Coloring Trees DP

    C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...

  6. CodeForces #369 C. Coloring Trees DP

    题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少.   K:连续的颜色为一组 ...

  7. CodeForces 149D Coloring Brackets

    Coloring Brackets time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  8. C. Coloring Trees DP

    传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...

  9. codeforces 711C C. Coloring Trees(dp)

    题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. 【.NET 6】多线程的几种打开方式和代码演示

    前言: 多线程无处不在,平常的开发过程中,应该算是最常用的基础技术之一了.以下通过Thread.ThreadPool.再到Task.Parallel.线程锁.线程取消等方面,一步步进行演示多线程的一些 ...

  2. java标识符 identifier

    1,标识符 --> 类名 方法名  变量名 常量名 接口名   为程序员自己命名的内容 main也是标识符但是不能修改 2, 命名规则 只能以   数字 字母(中文) 下划线 美元符号      ...

  3. Python-安装lmdb失败-解决方法

    使用pip install lmdb 时报错 ERROR: Command errored out with exit status 1: python setup.py egg_info Check ...

  4. 解决nginx反向代理Mixed Content和Blockable问题

    nginx配置https反向代理,按F12发现js等文件出现Mixed Content,Optionally-blockable 和 Blockable HTTPS 网页中加载的 HTTP 资源被称之 ...

  5. Linux文本查看工具

    文本查看工具 cat 特点: 不能用来看二进制文件 选项: -A: 显示不可见字符 cat支持标准输入: cat > aa.txt ---键盘作为标准输入,输出的结果重定向文件中去了 cat & ...

  6. 用python进行加密和解密——我看刑

    加密和解密 密码术意味着更改消息的文本,以便不知道你秘密的人永远不会理解你的消息. 下面就来创建一个GUI应用程序,使用Python进行加密和解密. 在这里,我们需要编写使用无限循环的代码,代码将不断 ...

  7. Java创建TXT文件并写入 内容

    public static void main(String[] args) { String filePath = "E:/" + "1.txt"; Stri ...

  8. Codeforces Round #804 (Div. 2)

    题目链接 A  The Third Three Number Problem 题意 给你一个n,让你求满足的a,b,c. 如果不存在则输出-1. 思路 显然任意a,b,c是不可能得到奇数. 只考虑偶数 ...

  9. NewApiDay03_File类

    File类创建一个新文件 File类的每一个实例可以表示硬盘(文件系统)中的一个文件或目录(实际上表示的是一个抽象路径) 使用File可以做到: 1:访问其表示的文件或目录的属性信息,例如:名字,大小 ...

  10. 丽泽普及2022交流赛day19 半社论

    目录 No Problem Str Not TSP 题面 题解 代码 Game 题面 题解 代码 No Problem 暴力 Str 存在循环节,大力找出来即可,长度显然不超过 \(10^3\) . ...