Test instructions: The player has an initial score, then a K-jury rating, which will be added to the player's score in turn, but the player remembers at some point in the process N (n<=k) a different score (in sequence), asking how many of the initial scores are possible.
Idea: Thinking problem +stl. First you can parse a K-score processing a prefix and find that the prefix and the same position in the two-moment fraction are the same, and then go through the unique function of the de-weight. You will then find the highlighted distinctin the topic, and the given N-known moment scores are different. So we have to construct an initial value to satisfy the existence of these n values, which can only be constructed from the number of CNT after the weight is removed. So enumerate the different prefixes of this CNT and, second-level enumeration n number, so as to determine an initial value, and then through the initial value to determine whether the third-level n number can pass the first CNT prefix and get.
Code:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int N = 8E6;
int A[MAXN], B[MAXN], PRE[MAXN];
int vis[2*n+5];
int k, n, base, ans, CNT, l;
Map<int, int> mp1;
int main ()
{
scanf ("%d%d", &k, &n);
for (int i = 1; I <= K; ++i) scanf ("%d", &a[i]);
for (int i = 1; I <= n; ++i) scanf ("%d", &b[i]);
Pre[0] = 0; Ans = 0;
for (int i = 1; I <= K; ++i) pre[i] = Pre[i-1]+a[i];
Sort (pre+1, pre+k+1);
CNT = unique (pre+1, pre+k+1)-pre;
for (int i = 1; i < cnt; ++i) ++mp1[pre[i];
for (int i = 1, i < cnt; ++i)
{for
(int j = 1; j <= N; ++j)
{
base = B[j]-pre[i];
if (Vis[base+n]) continue; Each base value is incremented by one ans
vis[base+n] = 1;
for (L = 1; l <= N, ++l)
{
if (mp1.find (b[l]-base) = = Mp1.end ()) break; Break small Optimization
}
if (l = = n+1) ++ans;}
}
printf ("%d\n", ans);
return 0;
}
Continue to Refuel ~