UVA 10714 Ants 蚂蚁 贪心+模拟 水题

时间:2023-03-08 23:23:10
UVA 10714 Ants 蚂蚁 贪心+模拟 水题

题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间。

模拟一下,发现其实灰常水的贪心。。。

不能直接求最大和最小的= =。只要求出每只蚂蚁都走长路下木棍时的最大值,和走短路时的就行了。

代码:

 /*
* Author: illuz <iilluzen@gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10714.cpp
* Lauguage: C/C++
* Create Date: 2013-08-29 22:52:12
* Descripton: UVA 10714 Ants, greed, simutation
*/
#include <cstdio>
#include <algorithm>
using namespace std; int main() {
int cas;
int Max, Min, len, n, t, L, S;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d", &len, &n);
Min = 0;
Max = 0;
while (n--) {
scanf("%d", &t);
if (t > len / 2) L = t, S = len - t;
else L = len - t, S = t;
Min = max(L, Min);
Max = max(S, Max);
}
printf("%d %d\n", Max, Min);
}
return 0;
}