codeforces 982B Bus of Characters

题意:

有n排座位,每排有两个座位,每排座位的宽度都不一样。

有2 * n个人要上车,如果是内向的人,那么它会选择一排两个都是空位并且宽度最小的一排去坐;

如果是外向的人,会选择一排座位已经有人坐的,并且宽度最大的一排。

输入数据保证外向的人一定可以找到合适的位置。

问每一个人坐的排数是多少。

思路:

用map存每个长度代表的座位,两个set存没有被占in的和已经被占ex的。

如果是内向的人,每次从没有被占的选择最小的,插入已经被占的,然后从没有被占中擦除;

如果是外向的人,直接从被占的选择一个最大的,再擦除。

感觉就是考察STL的运用。

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 #include <set>
 5 #include <map>
 6 using namespace std;
 7 const int N = 4e5 + 10;
 8 set<int> ex,in;
 9 map<int,int> mmp;
10 char s[N];
11 int main()
12 {
13     int n;
14     scanf("%d",&n);
15     for (int i = 1;i <= n;i++)
16     {
17         int x;
18         scanf("%d",&x);
19         in.insert(x);
20         mmp[x] = i;
21     }
22     scanf("%s",s);
23     for (int i = 0;i < 2 * n;i++)
24     {
25         if (s[i] == '0')
26         {
27             auto it = in.begin();
28             printf("%d ",mmp[*it]);
29             ex.insert(*it);
30             in.erase(*it);
31         }
32         else
33         {
34             auto it = ex.rbegin();
35             printf("%d ",mmp[*it]);
36             ex.erase(*it);
37         }
38     }
39     return 0;
40 }

 

posted @ 2018-05-18 03:22  qrfkickit  阅读(179)  评论(0编辑  收藏  举报