标签:cti fir stat adf hide force element preview elements
Codeforces Round #531 (Div. 3)
You are given an array aa consisting of nn integer numbers.
You have to color this array in kk colors in such a way that:
Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,…cnc1,c2,…cn, where 1≤ci≤k1≤ci≤k and cici is the color of the ii-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.
The first line of the input contains two integers nn and kk (1≤k≤n≤50001≤k≤n≤5000) — the length of the array aa and the number of colors, respectively.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤50001≤ai≤5000) — elements of the array aa.
If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers c1,c2,…cnc1,c2,…cn, where 1≤ci≤k1≤ci≤kand cici is the color of the ii-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.
4 2
1 2 2 3
YES
1 1 2 2
5 2
3 2 1 2 3
Output
YES
2 1 1 2 1
用k的颜色填充n个数字,k个颜色要用完,每种数字的颜色不能一样。
原本知道肯定是排序,但是我只能保证有这种情况,肯定小于等于k,不能保证k一定用完。
看了题解。排序,然后第k个数是第k个颜色。第k+1的数是第1种颜色。
保证有k个颜色。
不会vector
感觉我这种数据一大就会tle。死亡。
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<map> 6 #include<set> 7 #include<algorithm> 8 #include<cmath> 9 #include<cstdlib> 10 using namespace std; 11 int n, k,b[5100]; 12 struct student 13 { 14 int shu, zhi,id; 15 }a[5100]; 16 int cmp1(student x, student y) 17 { 18 return (x.shu < y.shu); 19 } 20 int cmp2(student x, student y) 21 { 22 return (x.id < y.id); 23 } 24 int main() 25 { 26 scanf("%d %d",&n,&k); 27 for (int i = 1; i <= n; i++) 28 { 29 scanf("%d",&a[i].shu); 30 b[a[i].shu]++; 31 a[i].id = i; 32 } 33 sort(a + 1, a + n + 1, cmp1); 34 int maxx = 0; 35 for (int i = 1; i <= 5000; i++) 36 maxx = max(b[i],maxx); 37 if (maxx > k) 38 { 39 printf("NO\n"); 40 return 0; 41 } 42 int kk = 0; 43 for (int i = 1; i <= n; i++) 44 { 45 a[i].zhi = kk % k + 1; 46 kk++; 47 } 48 sort(a + 1, a + n + 1, cmp2); 49 printf("YES\n"); 50 for (int i = 1; i <= n; i++) 51 { 52 if (i == 1) printf("%d",a[i].zhi); 53 else printf(" %d",a[i].zhi); 54 } 55 printf("\n"); 56 return 0; 57 }
Codeforces Round #531 (Div. 3)
标签:cti fir stat adf hide force element preview elements
原文地址:https://www.cnblogs.com/Kaike/p/10259331.html