题目
神奇的原因,又没法复制题目,一复制就说我非原创。
给大家个链接
题目传送门
思路
这题,就是一道智力冲浪题 (水题)。
做了这道题,我想起了洛谷的一句话。
有些问题刚开始觉得无从下手。好好想一想,尽量别看题解,否则你会大呼“简单”。
蚂蚁数上限
1000000
1000000
1000000,爬行方式
2
1000000
2^{1000000}
21000000种。
(默默放弃这一题)
这一题,两只蚂蚁碰面后,会转身再走。
emmmm,给大家看两幅盗来的图。
(由于盗图,请忽略引号)
本来两只蚂蚁的行走轨迹:
相遇转身后:
(换魂大法好!)
这不就相当于没有转身这个限制了吗。
于是,我们将每个蚂蚁的运动最短时间和最长时间都求出来,分别取最大值,就完事了。
很快活。
代码
#include <cstdio>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <queue>
#include <istream>
#include <ostream>
#include <set>
#include <stack>
#include <cwctype>
#include <fstream>
#include <vector>
#include <cwchar>
#include <functional>
using namespace std;
int main() {
int T; scanf("%d", &T);
while (T--) {
int l, n; scanf("%d%d", &l, &n);
int ans1, ans2; ans1 = ans2 = 0;
for (int i = 1, x; i <= n; i++) {
scanf("%d", &x);
ans1 = max(ans1, min(x, l-x));
ans2 = max(ans2, max(x, l-x));
}
printf("%d %d\n", ans1, ans2);
}
return 0;
}
(请忽略我这些可爱的头文件)