洛谷 1007 独木桥

这题很水

但是他给我们提供了一个很好的思路

 

两个人相遇时反向行走是不是就相当于这两个人从对方的身体中穿过去了呢?

那么这道题就解决了

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 int l,n,x,minn,maxn;
 7 int main()
 8 {
 9     scanf("%d %d",&l,&n);
10     for(int i=1;i<=n;i++)
11     {
12         scanf("%d",&x);
13         minn=max(min(x,l+1-x),minn);
14         maxn=max(max(x,l+1-x),maxn);
15     }
16     printf("%d %d\n",minn,maxn);
17     return 0;
18 }

是不是很水?

posted @ 2018-10-17 11:08  没有名字的大佬  阅读(158)  评论(0编辑  收藏  举报