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 Sinit at 2016-12-27 11:25:36 on Problem 1852
蚂蚁相遇时的掉头等价于穿过。。。明白这一点问题就很简单了
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int len, n, i, t, pos, longest, shortest, temp;
	scanf("%d", &t);
	while( t-- )
	{
		scanf("%d%d", &len, &n);
		for( i=0, longest=0, shortest=0; i<n; i++)
		{
			scanf("%d", &pos);
			temp = max(pos, len-pos);
			longest = max(longest, temp);
			temp = min(pos, len-pos);
			shortest = max(shortest, temp);
		}
		printf("%d %d\n", shortest, longest);
	}
	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