1. 程式人生 > >CF831C Jury Marks

CF831C Jury Marks

turn 其他 style using 插入 ios name bre mes

思路:

關鍵在於“插入”一個得分之後,其他所有得分也隨之確定了。

實現:

 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 }

CF831C Jury Marks