Build a Contest-创建比赛 CodeForce1100B

题目链接:Build a Contest

题目原文

  Arkady coordinates rounds on some not really famous competitive programming platform. Each round features 𝑛 problems of distinct difficulty, the difficulties are numbered from 1 to 𝑛.

  To hold a round Arkady needs 𝑛 new (not used previously) problems, one for each difficulty. As for now, Arkady creates all the problems himself, but unfortunately, he can't just create a problem of a desired difficulty. Instead, when he creates a problem, he evaluates its difficulty from 1 to 𝑛 and puts it into the problems pool.

  At each moment when Arkady can choose a set of 𝑛n new problems of distinct difficulties from the pool, he holds a round with these problems and removes them from the pool. Arkady always creates one problem at a time, so if he can hold a round after creating a problem, he immediately does it.

  You are given a sequence of problems' difficulties in the order Arkady created them. For each problem, determine whether Arkady held the round right after creating this problem, or not. Initially the problems pool is empty.

题目大意

阿尔卡迪管理着一个程序竞赛平台。每个题目的难度都会被分成1-n,n个等级。每次创建比赛的时候需要难度为1-n的试题。每次出题都会把题目放入题库中,已知一个阿尔卡迪每次出题难度的序列,在阿尔卡迪能够创建一场比赛的时候输出1.

思路

用一个数组来存剩余的每种难度的题目的数量,如果1-n全不为0,就说明可以开contest了。然后把所有元素都减去1。

题解

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 int level, num, tmp, flg;
 5 int vis[100005];
 6 
 7 using namespace std;
 8 
 9 int main(int argc, char const *argv[])
10 {
11     cin >> level >> num;
12     flg = level;    //记录缺几种难度的题目
13     for(int i = 0; i < num; i++)
14     {
15         cin >> tmp;
16         if (vis[tmp]++ == 0)    //之前没有出现过难度为i的题目
17         {
18             flg--;
19         }
20         if(flg == 0)            //题库里有所有难度的题目
21         {
22             cout << 1;
23             flg = level;
24             for(int j = 1; j <= level; j++)
25             {
26                 vis[j]--;
27                 if (vis[j] > 0) 
28                 {
29                     flg--;
30                 }
31             }
32         }
33         else
34         {
35             cout << 0;
36         }
37     }
38     return 0;
39 }

 

posted @ 2019-02-17 21:58  SaltyFishQF  阅读(480)  评论(0编辑  收藏  举报