洛谷1007 独木桥

原题链接
水题。
因为全部人走路速度是一样的,所以当两个人相遇时转身走就相当于与直接穿过去。
因此每个人都是独立的,而每个人开始有两个方向去走,取个(max)(min)就好。

#include<cstdio>
using namespace std;
inline int re()
{
	int x = 0;
	char c = getchar();
	bool p = 0;
	for (; c < '0' || c > '9'; c = getchar())
		p |= c == '0';
	for (; c >= '0' && c <= '9'; c = getchar())
		x = x * 10 + c - '0';
	return p ? -x : x;
}
inline int maxn(int x, int y) { return x > y ? x : y; }
inline int minn(int x, int y) { return x < y ? x : y; }
int main()
{
	int i, n, m, x, mi = 0, ma = 0;
	m = re(); n = re();
	for (i = 1; i <= n; i++)
	{
		x = re();
		mi = maxn(mi, minn(x, m + 1 - x));
		ma = maxn(ma, maxn(x, m + 1 - x));
	}
	printf("%d %d", mi, ma);
	return 0;
}
原文地址:https://www.cnblogs.com/Iowa-Battleship/p/10079576.html