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 |
贪心还是可以解的,反过来想,比M档次更低的车一定在M之后参看的大神代码才弄懂, 用vector两维会超时 #include <cstdio> #include <vector> #include <algorithm> #include <deque> using namespace std; typedef pair<int, int > KART; vector<KART > kart; deque<vector<KART > > rank; int main() { //freopen("nimo.in", "r", stdin); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); kart.push_back(KART(x, y)); } sort(kart.begin(), kart.end()); for (vector<KART>::reverse_iterator it = kart.rbegin(); it != kart.rend(); ++it) { if (rank.empty() || rank.back().back().second >= it->second) { rank.push_back(vector<KART >(1, *it)); } else { int s = 0, e = rank.size(); while (s + 1 < e) { int mid = (s + e) >> 1; if (rank[mid].back().second >= it -> second) s = mid; else e = mid; } if (e == rank.size() || rank[s].back().second < it->second) e = s; rank[e].push_back(*it); } } for (deque<vector<KART > > ::iterator it = rank.begin(); it != rank.end(); ++it) { printf("%d:", it->size()); for (vector<KART>::reverse_iterator i = it->rbegin(); i != it->rend(); ++i) printf(" (%d,%d)", i->first, i->second); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator