首页 > 代码库 > HDU 5360: Hiking
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。