Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
数据很水,STL都可以0MS.附1000B代码const int N = 30; int n, pos[N], x, y, i; deque<int> d[N], tmp; string s1, s2; signed main(void) { ios::sync_with_stdio(false); for (cin >> n, i = 0; i < n; i++)pos[i] = i, d[i].push_back(i); while (cin >> s1 && s1[0] != 'q') { cin >> x >> s2 >> y; if (pos[x] == pos[y])continue; if (s1[0] == 'm')while (d[pos[x]].back() != x)d[d[pos[x]].back()].push_back(d[pos[x]].back()), pos[d[pos[x]].back()] = d[pos[x]].back(), d[pos[x]].pop_back(); if (s2[1] == 'n')while (d[pos[y]].back() != y)d[d[pos[y]].back()].push_back(d[pos[y]].back()), pos[d[pos[y]].back()] = d[pos[y]].back(), d[pos[y]].pop_back(); while (tmp.empty() || tmp.back() != x)tmp.push_back(d[pos[x]].back()), d[pos[x]].pop_back(); while (!tmp.empty())d[pos[y]].push_back(tmp.back()), pos[tmp.back()] = pos[y], tmp.pop_back(); } for(i=0;i<n&&cout<<i<<": ";cout<<endl,i++)while (!d[i].empty())cout << d[i].front() << " ", d[i].pop_front(); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator