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 |
wa 到死, 哪位看看#include <iostream> #include <algorithm> #include <string> #include <vector> #include <sstream> using namespace std; const int N = 200; vector<int> tr[N]; int deg[N], a[N], b[N]; void Print(int u) { flag[u] = true; cout << "(" << u; for (vector<int>::iterator it = tr[u].begin(); it != tr[u].end(); ++it) { cout << " "; Print(*it); } cout << ")"; } int main() { string buf; int n, i, m, x; while (getline(cin, buf)) { stringstream ss(buf); for (n = 0; ss >> a[n]; n++); n = n + 1; memset(deg, 0, sizeof(deg)); for (i = 0; i < n - 1; i++) deg[a[i]]++; m = 0; for (i = 1; i <= n; i++) if (deg[i] == 0) b[m++] = i; make_heap(b, b + m, greater<int>()); for (i = 1; i <= n; i++) tr[i].clear(); for (i = 0; i < n - 1; i++) { x = b[0]; b[0] = b[--m]; pop_heap(b, b + m, greater<int>()); tr[a[i]].push_back(x); if (--deg[a[i]] == 0) { b[m++] = a[i]; push_heap(b, b + m, greater<int>()); } } Print(n); cout << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator