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 ...
随机推荐
- 在生产中部署ML前需要了解的事
在生产中部署ML前需要了解的事 译自:What You Should Know before Deploying ML in Production MLOps的必要性 MLOps之所以重要,有几个原因 ...
- python PIL 图片素描化
from PIL import Image import numpy as np a = np.asarray(Image.open("D://7.jpg").convert('L ...
- dubbo的消费者是怎么获取提供者服务接口引用的?
本文主要解读dubbo消费者是如何引用服务端接口的,是如何像本地调用一样调用远程服务的. 并试着从设计者的角度思考,为何这样设计. @Component public class DubboConsu ...
- generatorConfig.xml自动生成实体类,dao和xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration ...
- JS:对象调方法1
找调用者 1.如果有this,就先看this在哪个函数中,就是离this最近的function,没有就是window 2.找到函数后,辨别哪个是调用者 例1: 点击查看代码 function fn() ...
- 03 转换css元素的类别
03 转换css元素的类别 通过设置display属性 属性 作用 block 块级 inline 行内 inline-block 行内块级 接来下 就跟着小demo来学习吧! 不懂可以看看!!!什么 ...
- Elasticsearch 在地理信息空间索引的探索和演进
vivo 互联网服务器团队- Shuai Guangying 本文梳理了Elasticsearch对于数值索引实现方案的升级和优化思考,从2015年至今数值索引的方案经历了多个版本的迭代,实现思路从最 ...
- ansible-playbook批量修改密码
1. 将服务器ip写到ansible hosts文件中 2. 实现免密登录服务器 将ansible服务器公钥拷贝到目标服务器用户目录下的.ssh/authorized_keys 手动连接一次或者自己写 ...
- 8.4 苹果macOS电脑如何安装Java开发环境(JDK)
和Windows电脑安装差不多. 下载 来到JDK官方下载界面,点击Java SE 8(简称JDK 8)后面的JDK下载,来到该界面,先同意协议,然后下载对应平台的JDK,我们这里下载Mac OS X ...
- wsl2安装百度apollo及其基本配置
一. wsl2的开启 首先 WSL2 gui 需要Windows 11 Build 22000版本以上才支持 利用管理员权限打开PowerShell 执行 dism.exe /online /enab ...