哇靠,做了一晚上题,刚开始各种模拟,一直超时,换了快读多过了一个样例,无了无了!刚进组的acmer代码太小白莫怪莫怪。先说一下思路吧,题目大意就是从数组里面找一对数,假设为x,y,如果x%y的结果在刚输入的数组中不存在,就输出,否则,就不输出,一共输出数组长度的一半多个;
技巧:找出数组中最小的数,令y为最小的数,无论x是多少,x%y的值都不在数列中。废话不多说,上代码
// Problem: CF1613B Absent Remainder
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1613B
// Memory Limit: 250 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define ios \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 2e5 + 10;
inline int read() //快读
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll a[maxn];
bool cmp(ll x, ll y)
{
return x < y;
}
int main()
{
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int minn = 2e5 + 10;
for (int h = 1; h <= n; h++) {
a[h] = read();
minn = a[h] > minn ? minn : a[h];
}
sort(a + 1, a + n + 1, cmp);//从大到小排序,不排序也可以,需特判
int i, k, flag, ans = 0; //最小值等于数组自己的情况
for (i = n; i >= 2 && ans != n / 2; i--) {//for循环可以有
cout << a[i] << " " << minn << endl; //多个判断条件
ans++; //记录输出了几组数据
}
}
return 0;
}