链接: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. php个性代码注释

      // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // . ' \ ...

  2. python基础知识-day7(文件操作)

    1.文件IO操作: 1)操作文件使用的函数是open() 2)操作文件的模式: a.r:读取文件 b.w:往文件里边写内容(先删除文件里边已有的内容) c.a:是追加(在文件基础上写入新的内容) d. ...

  3. UiPath存在文本Text Exists的介绍和使用

    一.Text Exists的介绍 检查是否在给定的UI元素中找到了文本,输出的是一个布尔值 二.Text Exists在UiPath中的使用 1. 打开设计器,在设计库中新建一个Sequence,为序 ...

  4. ArrayList分析1-循环、扩容、版本

    ArrayList分析1-循环.扩容.版本 转载请注明出处 https://www.cnblogs.com/funnyzpc/p/16407733.html 前段时间抽空看了下ArrayList的源码 ...

  5. NC15163 逆序数

    NC15163 逆序数 题目 题目描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.比如一个序列为 \ ...

  6. Trie 树进阶学习笔记

    前言 没脑子选手发现自己什么都不会 ... \(\text{More and more vegetables, What should I do?}\) 正文 Trie 树简介 大概是人类的话都知道吧 ...

  7. java 九九乘法表(for循环)

    package study5ran2yl.study; public class ForDemo01 { public static void main(String[] args) { int h; ...

  8. Note -「0/1 Fractional Programming」

    What is that? Let us pay attention to a common problem that we often meet in daily life: There are \ ...

  9. 基于ABP实现DDD--仓储实践

      由于软件系统中可能有着不同的数据库,不同的ORM,仓储思想的本质是解耦它们.在ABP中具体的实现仓储接口定义在领域层,实现在基础设施层.仓储接口被领域层(比如领域服务)和应用层用来访问数据库,操作 ...

  10. Class对象功能概述和Class对象功能获取Field

    Constructor[] getConstructors() Constructor getConstructor(类... parameterTypes) Constructor getDecla ...