POJ 1852 Ants

来源:互联网 发布:给淘宝刷好评是真的吗 编辑:程序博客网 时间:2024/05/18 22:43

理解题意就很简单。

一条木棍上有很多蚂蚁,全都面朝木棍中间的位置爬行。

两个相遇就都掉头爬行,这可以理解为两个蚂蚁互相之间没有干扰。(swap一下)。


这样只需要找距离两头的距离就好了。


#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<vector>#include<cmath>#define INF 0x7fffffff#define eps 1e-8#define LL long long#define PI 3.141592654#define CLR(a,b) memset(a,b,sizeof(a))#define FOR(i,a,n) for(int i= a;i< n ;i++)#define FOR0(i,a,b) for(int i=a;i>=b;i--)#define pb push_back#define mp make_pair#define ft first#define sd second#define sf scanf#define pf printf#define acfun std::ios::sync_with_stdio(false)#define SIZE 10000+1using namespace std;int m,n;int main(){    int t;    sf("%d",&t);    while(t--)    {        sf("%d%d",&m,&n);        int maxn=-INF,minn=-INF;        FOR(i,0,n)        {            int tmp;            sf("%d",&tmp);            maxn=max(maxn,max(tmp,m-tmp));            minn=max(minn,min(tmp,m-tmp));        }        pf("%d %d\n",minn,maxn);    }}


0 0
原创粉丝点击