栈应用--Codeforces Round #205 (Div. 2)B

来源:互联网 发布:ae软件都能做什么 编辑:程序博客网 时间:2024/04/28 16:26

自己写的代码还是太挫啊。。。

#include <iostream>#include <stack>using namespace std;int n;stack<int> ids[101];int hp[200];int df[2];int main(){    cin >> n;    for (int i = 0; i < 2*n; i++)    {        int a;        cin >> a;        ids[a].push(i);    }    int x = 0;    for (int i = 0; i <= 100; i++)        if (ids[i].size() == 1)        {            int id = ids[i].top();            ids[i].pop();            hp[id] = x;            df[x]++;            x = (x+1)%2;        }    for (int i = 0; i <= 100; i++)        if (!ids[i].empty())        {            df[0]++;            df[1]++;            while (!ids[i].empty())            {                int id = ids[i].top();                ids[i].pop();                hp[id] = x;                x = (x+1)%2;            }        }    cout << df[0]*df[1] << "\n";    for (int i = 0; i < 2*n; i++)        cout << hp[i]+1 << " ";    return 0;}


原创粉丝点击