Educational Codeforces Round 93 (Rated for Div. 2)

A. Bad Triangle

Educational Codeforces Round 93 (Rated for Div. 2) - 图1

input

  1. 3
  2. 7
  3. 4 6 11 11 15 18 20
  4. 4
  5. 10 10 10 11
  6. 3
  7. 1 1 1000000000

output

  1. 2 3 6
  2. -1
  3. 1 2 3

Note

In the first test case it is impossible with sides Educational Codeforces Round 93 (Rated for Div. 2) - 图2. Note, that this is not the only correct answer.

In the second test case you always can construct a non-degenerate triangle.

题意:

在非递减序列中找坏三角形。

思路:

由于是非递减的序列,直接特判Educational Codeforces Round 93 (Rated for Div. 2) - 图3

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn = 1e5;
  5. ll a[maxn];
  6. bool check(ll x, ll y, ll z) {
  7. if (x + y <= z || x + z <= y || y + z <= x)
  8. return false;
  9. return true;
  10. }
  11. void solve() {
  12. int n; cin >> n;
  13. bool flag = false;
  14. for (int i = 1; i <= n; ++i)cin >> a[i];
  15. if (!check(a[1], a[2], a[n])) {
  16. cout << 1 << " " << 2 << " " << n << endl;
  17. }
  18. else if (!check(a[1], a[n - 1], a[n]))
  19. cout << 1 << " " << n - 1 << " " << n << endl;
  20. else cout << "-1" << endl;
  21. }
  22. int main() {
  23. //freopen("in.txt", "r", stdin);
  24. int t; cin >> t;
  25. while (t--)solve();
  26. }

B. Substring Removal Game

Educational Codeforces Round 93 (Rated for Div. 2) - 图4

题意:

Alice 和 Bob 又在玩游戏了,给出一个0,1构成的字符串,问在每个人都想得到最多分的情况下,Alice能得多少分(删去1的个数 = 所得分数)

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int maxn = 1e5;
  5. ll a[maxn];
  6. bool check(ll x, ll y, ll z) {
  7. if (x + y <= z || x + z <= y || y + z <= x)
  8. return false;
  9. return true;
  10. }
  11. void solve() {
  12. string s;cin >> s;
  13. vector<int>q;
  14. int cnt = 0;
  15. for (int i = 0; i < s.length(); ++i) {
  16. if (s[i] == '1')cnt++;
  17. else {
  18. if (cnt == 0)continue;
  19. q.push_back(cnt);
  20. cnt = 0;
  21. }
  22. }
  23. q.push_back(cnt);
  24. cnt = 0;
  25. sort(q.begin(), q.end());
  26. for (int i = q.size() - 1; i >= 0; i -= 2)
  27. cnt += q[i];
  28. cout << cnt << endl;
  29. }
  30. int main() {
  31. //freopen("in.txt", "r", stdin);
  32. int t; cin >> t;
  33. while (t--)solve();
  34. }

C. Good Subarrays

Educational Codeforces Round 93 (Rated for Div. 2) - 图5

题意:

给定一个Educational Codeforces Round 93 (Rated for Div. 2) - 图6个元素的序列a,求满足Educational Codeforces Round 93 (Rated for Div. 2) - 图7的区间个数.

  1. #include<bits/stdc++.h>
  2. using namespace std;int T,n;
  3. string s;map<int,int>mp;
  4. int main(){
  5. cin>>T;
  6. while(T--){mp.clear();
  7. cin>>n>>s;mp[0]++;
  8. long long ans=0,sum=0;
  9. for(int i=0;i<n;i++){
  10. sum+=s[i]-'1';
  11. ans+=mp[sum];mp[sum]++;
  12. }
  13. cout<<ans<<endl;
  14. }
  15. }

D. Colored Rectangles

Educational Codeforces Round 93 (Rated for Div. 2) - 图8

Examples

input

  1. 1 1 1
  2. 3
  3. 5
  4. 4

output

  1. 20

input

  1. 2 1 3
  2. 9 5
  3. 1
  4. 2 8 5

output

  1. 99

input

  1. 10 1 1
  2. 11 7 20 15 19 14 2 4 13 14
  3. 8
  4. 11

output

  1. 372

Educational Codeforces Round 93 (Rated for Div. 2) - 图9

题目大意:给定若干个红色,绿色,蓝色的一对长度一样的棍子.问用这些棍子组成的颜色不同的矩形的面积的最大总和是多少.注意不能把两个相同颜色的一对棍子拆成两个分别去用.其次颜色不同指的是在两个集合里选的两对棍子.

数据范围:

Educational Codeforces Round 93 (Rated for Div. 2) - 图10

思路

首先比较容易想到的是贪心,但是这个题会跟棍子的数目有关,贪心会有很多问题,而且打补丁的方式是解决不了的.

考虑O(n3)O(n3)的DP,由于一共就三种元素,不妨就直接按定义直接设计状态:

状态:Educational Codeforces Round 93 (Rated for Div. 2) - 图11表示红色用了i个,绿色用了j个,蓝色用了k个的前提下得到的矩形面积总和的最大值.

入口:全为0即可,不需要额外处理.

转移:三种匹配方式直接枚举即可.

出口:所有值的最大值.

注意点的话,防止int爆掉吧

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define int ll
  5. const int N = 205;
  6. int r[N],g[N],b[N];
  7. int f[N][N][N];
  8. signed main()
  9. {
  10. ios::sync_with_stdio(0);cin.tie(0);
  11. int R,G,B;cin >> R >> G >> B;
  12. for(int i = 1;i <= R;++i) cin >> r[i];sort(r + 1,r + R + 1,greater<int>());
  13. for(int i = 1;i <= G;++i) cin >> g[i];sort(g + 1,g + G + 1,greater<int>());
  14. for(int i = 1;i <= B;++i) cin >> b[i];sort(b + 1,b + B + 1,greater<int>());
  15. int res = 0;
  16. for(int i = 0;i <= R;++i)
  17. {
  18. for(int j = 0;j <= G;++j)
  19. {
  20. for(int k = 0;k <= B;++k)
  21. {
  22. auto& v = f[i][j][k];
  23. if(i >= 1 && j >= 1) v = max(v,f[i - 1][j - 1][k] + r[i] * g[j]);
  24. if(j >= 1 && k >= 1) v = max(v,f[i][j - 1][k - 1] + g[j] * b[k]);
  25. if(i >= 1 && k >= 1) v = max(v,f[i - 1][j][k - 1] + r[i] * b[k]);
  26. res = max(res,v);
  27. }
  28. }
  29. }
  30. cout << res << endl;
  31. return 0;
  32. }

E. Two Types of Spells

Educational Codeforces Round 93 (Rated for Div. 2) - 图12

Example

input

  1. 6
  2. 1 5
  3. 0 10
  4. 1 -5
  5. 0 5
  6. 1 11
  7. 0 -10

output

  1. 5
  2. 25
  3. 10
  4. 15
  5. 36
  6. 21