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 ...
随机推荐
- 百度地图API 地图圈区域并计算坐标点是否在区域内
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C++对象间通信组件,让C++对象“无障碍交流”
介绍 这是很久之前的一个项目了,最近刚好有些时间,就来总结一下吧! 推荐初步熟悉项目后阅读本文: https://gitee.com/smalldyy/easy-msg-cpp 从何而来 这要从我从事 ...
- SAP Web Dynpro-监视应用程序
您可以使用ABAP监视器来监视Web Dynpro应用程序. 存储有关Web Dynpro应用程序的信息. 您可以使用T代码-RZ20查看此信息. 您可以在Web Dynpro ABAP监视器中查看以 ...
- 获取请求体数据 POST
POST获取请求体 请求体中封装了 POST请求的请求参数 获取流对象 再从流对象中那数据 一种字节流 一种字符流 BufferedReader getReader()获取字符输入流 只能操作字符 S ...
- css-sticky 定位
前言 我们大多都了解绝对定位.相对定位.static 和 fixed 定位,而 sticky 定位常常会被忽略,本文来总结一下其相关使用方法. 正文 1.常见使用效果 我们滚动滚动条时,当 " ...
- shell脚本处理二进制数据
正确处理二进制数据 正确处理二进制数据必须保证以下三个环节是二进制安全(Binary Safe)的: 从文件读取至内存: 处理数据过程中: 内存写入至文件. 那么二进制安全是什么?通俗来说就是不会特殊 ...
- 快来体验快速通道,netty中epoll传输协议详解
目录 简介 epoll的详细使用 EpollEventLoopGroup EpollEventLoop EpollServerSocketChannel EpollSocketChannel 总结 简 ...
- 数据类型 简单扩展(Java)
public class HelloWorld { public static void main(String[] args) { //整数拓展 进制 二进制0b 十进制 八进制0 十六进制0x i ...
- 动手实践丨手把手教你用STM32做一个智能鱼缸
摘要:本文基于STM32单片机设计了一款基于物联网的智能鱼缸. 本文分享自华为云社区<基于STM32+华为云IOT设计的物联网鱼缸[玩转华为云]>,作者: DS小龙哥 . 1. 前言 为了 ...
- @Document注解与Lombok的区别