UVA 10714 Ants

Source: Internet
Author: User

Greedy, the ant-turn is equivalent to passing through, so in the middle as a distinguishing point, the shortest time is left to go to the left, right to the right, the longest time is left to the right to go, right to the left

1#include <iostream>2#include <cstdio>3#include <algorithm>4 #defineMAXN 10000005 6 using namespacestd;7 8 intt,mint,maxt,n,l;9 intMain ()Ten { Onescanf"%d",&T); A      while(t--) -     { -scanf"%d%d",&l,&n); the         intmid=l/2, A; -Mint=0, maxt=0; -          for(intI=0; i<n;i++) -         { +scanf"%d",&a); -             if(a>mid) +             { Amaxt=Max (maxt,a); atMint=max (mint,l-a); -             } -             Else -             { -Maxt=max (maxt,l-a); -Mint=Max (mint,a); in             } -         } toprintf"%d%d\n", mint,maxt); +     } -     return 0; the}
View Code

UVA 10714 Ants

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.