【CF1100B】Build a Contest

The meaning of problems

Do you have questions $ n $ and a $ k $, the difficulty of each question in between $ 1 $ and $ k $.

Each gather the $ k $ new topics of varying degrees of difficulty, it is necessary to hold a competition, includes $ 1 $ to $ k $ each a difficult topic.

Of course, it has been used in a competition held title will be void, can not be reused.

If you are out of the question for the first $ i $ a competition, then $ f (i) = 1 $, or $ f (i) = 0 $

Finally, let $ i $ the output of all $ f (i) $ sequentially from $ 1 $ to $ n $, separate and no spaces.

$ 1 \ n, k \ ^ 10 $ 5

Resolve

Obviously, we can find the number of times the game can be held, is the minimum number of questions $ 1 $ to $ k $ in each difficulty arise.

Then we can find a thing: if we are to host the $ x $ tournament, you need to know is the number of current topics every difficulty is not less than $ x $.

This thing very well ask, we just need online processing times each number a difficult topic appears.

Because every number is not greater than $ 10 $ ^ 5, a bucket can start recording the number of times the same difficulty occurs.

We define the array as $ cnt $ barrel, $ sum $ record their answers, $ sum_i $ is the number that has some of the $ i $ title before the tournament.

Then, for the number of $ p $ $ X $, so plus a $ cnt_x $, $ sum_ {cnt_x} = p $ can.

Finally, let $ X $ $ 1 $ pushed from $ \ min \ {cnt_i \} $, $ array by recording the answer ANS $ sequence, i.e., let $ ans_ {sum_x} = 1 $

Then the output can.

Reference Code

#include <cstdio>
#define N 100010

int k, n, a, cnt[N], sum[N], ans[N], minn = 1e9; inline int min(int a, int b){ return a < b ? a : b; } int main(){ scanf("%d%d", &k, &n); for(int i=1; i<=n; i++){ scanf("%d", &a); sum[++cnt[a]] = i; }
for(int i=1; i<=k; i++) minn = min(minn, cnt[i]); for(int i=1; i<=minn; i++) ans[sum[i]]++; for(int i=1; i<=n; i++) printf("%d", ans[i]); return 0; }

 

Guess you like

Origin www.cnblogs.com/zengpeichen/p/11520012.html