B2. Wonderful Coloring - 2
链接: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的更多相关文章
- 推荐一个iOS关于颜色的库-Wonderful
Wonderful 这个库主要是与UIColor息息相连的,其中一共包含四个子文件,UIColor+Wonderful,UIColor+Separate,SXColorGradientView,SXM ...
- 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 ...
- CF149D. Coloring Brackets[区间DP !]
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...
- 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 ...
- 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 ...
- CodeForces #369 C. Coloring Trees DP
题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少. K:连续的颜色为一组 ...
- CodeForces 149D Coloring Brackets
Coloring Brackets time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- C. Coloring Trees DP
传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...
- codeforces 711C C. Coloring Trees(dp)
题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- ShardingSphere-proxy-5.0.0分布式雪花ID生成(三)
一.目的 保证在分库分表中每条数据具有唯一性 二.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Founda ...
- Elasticsearch学习系列三(搜索案例实战)
Query DSL Es提供了基于JSON的完整查询DSL(Domain Specific Language 特定域的语言)来定义查询.将查询DSL视为查询的AST(抽象语法树).它由两种子句组成: ...
- sap 获取设置的打印机参数
*&---------------------------------------------------------------------* *& Form FRM_SET_PRI ...
- Freeswitch使用originate转dialplan
概述 Freeswitch是一款非常好用的开源VOIP软交换平台. 最近在对fs做一些功能测试,测试的过程中产生的一个需求,如何从fs发起呼叫并把后续的呼叫流程转到某一个dialplan上,这样在测试 ...
- 谷歌浏览器控制台 f12怎么设置成中文/英文 切换方法,一定要看到最后!!!
1.打开谷歌浏览器 2.右键选择检查或 f12 打开控制台 3.点击控制台右边的设置 4.中切英 选择偏好设置->语言=>English 5.英切中 6.选择中文 7.重启 8.切换中文成 ...
- git stash 的一次惊心动魄的误删操作
git stash 的一次惊心动魄的误删操作 简介:行走在互联网最低端的小熊 问题--源起: 小熊和所有混迹在互联网中的开发一样,公司里面用git来管理项目,由于可能经常有几个问题要开发,要频繁在多分 ...
- python小题目练习(十二)
题目:如下图所示 代码展示: """Author:mllContent:春节集五福Date:2020-01-17"""import rand ...
- 论文解读(AGC)《Attributed Graph Clustering via Adaptive Graph Convolution》
论文信息 论文标题:Attributed Graph Clustering via Adaptive Graph Convolution论文作者:Xiaotong Zhang, Han Liu, Qi ...
- Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-b1938128a963
报错信息:Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait ...
- CentOS7使用LVM缩减/home空间,扩大/空间
CentOS7使用LVM缩减/home空间,扩大/空间方法:把/home里的内容备份,然后将/home文件系统所在的逻辑卷删除,扩大/文件系统.新建/home,恢复/home的原内容1.查看默认分区[ ...