三晋七校第一届新生赛(同步赛)_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ
F 和移位

最后剩余1h才开始写这道题的,虽然有了一点思路但是已经没时间写了。我观察到n的大小只有2000,所以我觉得可以先用n^2构造一个数组出来,然后进行后续的处理。
当然,比完赛后自己写了下写出来了,真的是太棒了OvO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 1e5 + 10;
int x, n, q; int a[N];
map<int, vector<int> > mp; map<int, int> dis;
int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (mp[a[i] + a[j]].empty()) mp[a[i] + a[j]].resize(2010); if (j <= i) mp[a[i] + a[j]][i - j]++; else mp[a[i] + a[j]][n - (j - i)]++; } for (auto &vec : mp) { vector<int> v = vec.second; int t = 0; for (int i = 1; i <= 2000; i++) if (v[i] > v[t]) t = i; dis[vec.first] = t; } while (q--) { cin >> x; cout << dis[x] << endl; } return 0; }
|