POJ-1852-Ants

來源:互聯網
上載者:User

標籤:http   io   os   ar   for   sp   代碼   amp   時間   

題目連結

http://poj.org/problem?id=1852

n只螞蟻以每秒1cm的速度在長為Lcm的竿子上爬行。當螞蟻爬到竿子的端點就會掉落。由於竿子太細,兩隻螞蟻相遇時,他們不能交錯通過,

只能各自反相爬回去,對於螞蟻,我們知道他距竿子左端的距離xi,  但不知道他當前的朝向。請計算所有螞蟻落下竿子所需的最短時間和最長時間。

Sample Input

210 32 6 7214 711 12 7 13 176 23 191

Sample Output

4 838 207


代碼

#include<iostream>
#include<cstdio>
using namespace std;

int a[1000005];

int main(void)
{
int t,n,m;
int i,j,k;
scanf("%d",&t);
while(t--)
{
int minn=0,maxx=0;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%d",a+i);
minn=max(minn,min(n-a[i],a[i]));
maxx=max(maxx,max(n-a[i],a[i]));
}
printf("%d %d\n",minn,maxx);
}
return 0;
}




POJ-1852-Ants

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.