http://codeforces.com/problemset/problem/1399/C
双指针,枚举2-2*n。
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
typedef long long ll;
ll gcd(ll a, ll b)
{return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {return a* b / (gcd(a, b));
}
#define PII pair<int,int>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int qmi(int a, int k, int p) //快速幂模板
{int res = 1;while (k){if (k & 1) res = (ll)res * a % p;k >>= 1;a = (ll)a * a % p;}return res;
}
///////////////////////////////////////////////////////////
int a[N];
int main()
{int t;cin >> t;while (t--) {int n;cin >> n;for (int i = 1; i <= n; i++)cin >> a[i];sort(a + 1, a + 1 + n);int ans = 0;for (int i = 2; i <= 100; i++) {int cnt = 0;int l = 1; int r = n;while (l < r) {if (a[l] + a[r] == i) {cnt++;ans = max(ans, cnt);l++;r--;}else if (a[l] + a[r] > i) {r--;}else if (a[l] + a[r] < i) {l++;}}}cout << ans << endl;}
}
刚开始当成思维题写了,果然菜的真实