1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 /*Test instructions: the longest and shortest time for all ants to go down the long pole*/7 8 /*Shortest time: First find out the shortest time for each ant to walk down the bar. Then find the maximum value of the shortest time9 Maximum time: Ask each ant to walk down the pole for the longest time. And then find the maximum value for the longest time.*/Ten One intMaxintAintb) { A if(A > B)returnA; - Else - returnb; the } - intMinintAintb) { - if(A < b)returnA; - Else returnb; + } - classant{ + Private: A intPolelenth; at intAntnum; - intMintime; - intMaxTime; - Public: - voidReadData (); - voidprocess (); in }; - voidAnt::readdata () { to intcases; +scanf"%d",&cases); - while(cases--){ theMintime =-1; *MaxTime =-1; $scanf"%d%d",&polelenth,&antnum);Panax Notoginseng for(inti =0; I < antnum;i++){ - process (); the } +cout<<mintime<<" "<<maxTime<<Endl; A } the } + voidAnt::p rocess () { - intLocal; $scanf"%d",&local); $Mintime = Max (Mintime,min (Local,polelenth-local)); -MaxTime = Max (Maxtime,max (Local,polelenth-local)); - } the - intMain ()Wuyi { the ant ant; - Ant.readdata (); Wu return 0; -}
UVa 10714-ants