思路:
关键在于“插入”一个得分之后,其他所有得分也随之确定了。
实现:
1 #include <iostream> 2 #include <cstdio> 3 #include <set> 4 using namespace std; 5 const int MAXN = 2005; 6 int a[MAXN], b[MAXN], sum[MAXN]; 7 int main() 8 { 9 int k, n; 10 set<int> ans; 11 cin >> k >> n; 12 for (int i = 1; i <= k; i++) 13 { 14 cin >> a[i]; 15 sum[i] = sum[i - 1] + a[i]; 16 } 17 for (int i = 1; i <= n; i++) cin >> b[i]; 18 for (int i = 1; i <= k; i++) 19 { 20 set<int> s; 21 for (int j = 1; j <= k; j++) 22 { 23 if (i == j) continue; 24 s.insert(b[1] - (sum[i] - sum[j])); 25 } 26 bool flg = true; 27 for (int j = 2; j <= n; j++) 28 { 29 if (!s.count(b[j])) { flg = false; break; } 30 } 31 if (flg) ans.insert(b[1] - sum[i]); 32 } 33 cout << ans.size() << endl; 34 return 0; 35 }
时间: 2024-11-05 21:45:14