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

几个月前看过,但就是想不明白,今天一见,其实是很简单的题!

Posted by alpc47 at 2008-09-30 16:14:31 on Problem 2726
对砂distance排一下序, 再一次扫描即可!!
因为题目限定的两个条件是一样的,所以只排一次序!
参考:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 10010;
struct dd { int d, c; } a[N];
int n;

bool operator < (const dd & a, const dd & b)
{
	if (a.d != b.d) return a.d < b.d;
	return a.c < b.c;
}

int main()
{
	while (scanf("%d", &n), n)
	{
		int i;
		for (i=0; i<n; i++) scanf("%d%d", &a[i].d, &a[i].c);
		sort(a, a+n);

		int ans = 0, mi = 1000000;
		for (i=0; i<n; i++)
			if (a[i].c < mi) { ans ++; mi = a[i].c; }
		printf("%d\n", ans);
	}

	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