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

排序 后查找,查找可以做到O(N)...N是输入的牛长度的数目...

Posted by Desertangle at 2010-12-01 22:46:58 on Problem 3663 and last updated at 2010-12-01 22:50:57
	sort(len, len + n);
	int res = 0;
	int pos = n - 1;
	int current = 0;
	while(pos > current)
	{
		if(len[pos] + len[current] <= s)
		{
			res += pos - current;
			++current;
		}
		else --pos;
	}
	printf("%d", res);

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