Codeforces Round #539 (Div. 2)

Topic links: http://codeforces.com/contest/1113

A: greedy, begins to fill, followed by a stop plus a stop.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     std::ios::sync_with_stdio(false);
 6     int n, k;
 7     cin >> n >> k;
 8     n -= 1;
 9     int ans = 0;
10     if(k >= n) ans = n;
11     else{
12         for(int i = 1;i <= n - k;i++) ans += i + 1;
13         years + = k;
14      }
 15      cout << age << endl;
16      return  0 ;
17 }
View Code

B: pretreatment, all within 100 changes, minus gotta change with the most minimal is the answer, do not start looking at the number two can only changed.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn =105;
 4 int vis[maxn];
 5 int d[maxn][maxn];
 6 int main()
 7 {
 8     std::ios::sync_with_stdio(false);
 9     int n;
10     cin >> n;
11     int a = 0;
12     int sum = 0;
13     for(int i = 0;i < n;i++) cin >> a, sum += a, vis[a] ++;
14     for(int i = 1;i <= 100;i++)
15         for(int j = 1;j <= 100;j++){
16             for(int k = 1;k <= i;k ++)
17             {
18                 if(i % k == 0)
19                 {
20                     d[i][j] = max(d[i][j], i + j - i/k - j*k);
21                 }
22             }
23         }
24     int ans = 0;
25     for(int i = 1;i <= 100;i++)
26     {
27         if(!vis[i]) continue;
28         for(int j = 1;j <= 100;j++)
29         {
30             if(vis[j]) ans = max(ans, d[i][j]);
31         }
32     }
33     cout << sum - ans << endl;
34     return 0;
35 }
View Code

C: seeking prefix and XOR, because a number of exclusive OR itself is 0, the same value before and after the interval XOR or exclusive, and can maintain a prefix to find. I learned a unordered_map

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 3e5 + 5;
 5 ll a;
 6 ll sum[maxn];
 7 unordered_map<int,int > mp[2];
 8 int main()
 9 {
10     int n;
11     cin >> n;
12  
13     for(int i= 1;i <= n;i++) cin >> a,sum[i] = sum[i - 1]^a;
14     ll ans = 0;
15     for(int i = 0;i <= n;i++)
16     {
17         int t = i%2;
18         if(mp[t].count(sum[i])) ans += mp[t][sum[i]];
19         if(mp[t].count(sum[i])) mp[t][sum[i]] ++;
20         else mp[t][sum[i]] = 1;
21     }
22     cout << ans << endl;
23     return 0;
24 }
View Code

D: only 12 did not expect the two types and the cutting method, because the data can not check an output impossable discussing 2, only the substring are identical or complete conversion of the original and the same situation.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5 + 5;
 4 char s[maxn], a[maxn];
 5 int main()
 6 {
 7     int n;
 8     cin >> s;
 9     n = strlen(s);
10     bool flag = true;
11     for(int i = 1;i < n;i++) if(s[i] != s[0]) flag = false;
12     if(flag) cout << "Impossible" << endl;
13     else{
14         for(int i = 1;i < n;i++){
15             int cnt = 0;
16             for(int j = i;j < n;j++) a[cnt++] = s[j];
17             for(int j = 0;j < i;j++) a[cnt++] = s[j];
18             flag = true;
19             for(int j = 0;j < n;j++) if(a[j] != s[j]) flag = false;
20             if(flag) continue;
21             else{
22                 int l = 0, r = n - 1;
23                 bool vis = true;
24                 while(l <= r){
25                     if(a[l] != a[r]) vis = false;
26                     l++, r--;
27                 }
28                 if(vis){
29                         cout << "1" << endl;return 0;
30                 }
31             }
32         }
33         if(n%2 == 0) cout << "2" << endl;
34         else{
35                 bool vis = true;
36             for(int i = n / 2 - 1;i >= 1;i--){
37                 if(s[i] != s[0]) vis = false;
38             }
39             if(vis) cout << "Impossible" << endl;
40             else cout << "2" << endl;
41         }
42  
43     }
44     return 0;
45 }
View Code

 

Guess you like

Origin www.cnblogs.com/Carered/p/11366552.html