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

我的代码还不错吧。 就是stl耗时有点长呀。。。。。

Posted by Hacker_QC at 2010-03-01 07:52:17 on Problem 1456
#define F(i,m,n) for (int i = m; i < n; ++i)
std::vector<int> prods[10002];
std::multiset<int> sells;

int main() {
	int N, p, d, maxd;

	while (scanf("%d", &N) == 1) {
		memset(prods, 0, sizeof(prods));
		maxd = -1;
		F(i, 0, N) {
			scanf("%d %d", &p, &d);
			prods[d].push_back(p);
			if (d > maxd) maxd = d;
		}
		int sum = 0;
		sells.clear();
		for (int i = maxd; i > 0; --i) {
			F(j, 0, prods[i].size()) sells.insert(prods[i][j]);
			if (!sells.size()) continue;
			sum += *(--sells.end());
			sells.erase(--sells.end());
		}
		printf("%d\n",sum);
	}
	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