Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贪心还是可以解的,反过来想,比M档次更低的车一定在M之后

Posted by nimohunter at 2014-08-24 16:00:33 on Problem 3598
参看的大神代码才弄懂, 用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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator