HDU 5360: Hiking
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5360: Hiking相关的知识,希望对你有一定的参考价值。
Hiking
///@author Sycamore, ZJNU; ///@date 8/4/2017 #include<bits/stdc++.h> using namespace std; #define endl ‘\n‘ typedef long long ll; struct soda { int l, r, id; }; struct _1st { bool operator() (const soda &x, const soda &y) { if (x.l != y.l) return x.l>y.l; if (x.r != y.r)return x.r<y.r; return x.id<y.id; } }; struct _2nd { bool operator()(const soda &x, const soda &y) { if (x.r != y.r)return x.r>y.r; if (x.l != y.l) return x.l>y.l; return x.id<y.id; } }; int main() { ios::sync_with_stdio(false); //cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<soda>v(n); vector<queue<soda>>s(n + 1); for (int i = 0; i<n; i++) { cin >> v[i].l; } for (int i = 0; i<n; i++) { v[i].id = i + 1; cin >> v[i].r; s[v[i].l].push(v[i]); } int now; priority_queue<soda, vector<soda>, _2nd>pq; queue<int>ans; int cnt = 0; for (now = 0; now <= n; ) { while (!s[now].empty()) { pq.push(s[now].front()); s[now].pop(); } if (!pq.empty()) { if (pq.top().r >= now) { cnt++; ans.push(pq.top().id); pq.pop(); now++; } else { ans.push(pq.top().id); pq.pop(); } } else { for (auto &e : s) { while (!e.empty()) { ans.push(e.front().id); e.pop(); } } break; } if (now == n) { for (auto &e : s) { while (!e.empty()) { ans.push(e.front().id); e.pop(); } } while (!pq.empty()) { ans.push(pq.top().id); pq.pop(); } } } cout << cnt << endl; bool f = true; while (!ans.empty()) { if (!f)cout << ‘ ‘; else f = false; cout << ans.front(); ans.pop(); } cout << endl; } return 0; }
以上是关于HDU 5360: Hiking的主要内容,如果未能解决你的问题,请参考以下文章
hdu 2425 Hiking Trip (bfs+优先队列)