Educational Codeforces Round 93 (Rated for Div. 2)

A. Bad Triangle

input

3
7
4 6 11 11 15 18 20
4
10 10 10 11
3
1 1 1000000000

output

2 3 6
-1
1 2 3

Note

In the first test case it is impossible with sides \(6, 11 and 18\). Note, that this is not the only correct answer.

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

题意:

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

思路:

由于是非递减的序列,直接特判\(1,2,n, or, 1,n-1,n\)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
ll a[maxn];
bool check(ll x, ll y, ll z) {
if (x + y <= z || x + z <= y || y + z <= x)
return false;
return true;
}
void solve() {
int n; cin >> n;
bool flag = false;
for (int i = 1; i <= n; ++i)cin >> a[i];
if (!check(a[1], a[2], a[n])) {
cout << 1 << " " << 2 << " " << n << endl;
}
else if (!check(a[1], a[n - 1], a[n]))
cout << 1 << " " << n - 1 << " " << n << endl;
else cout << "-1" << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
int t; cin >> t;
while (t--)solve();
}

B. Substring Removal Game

题意:

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
ll a[maxn];
bool check(ll x, ll y, ll z) {
if (x + y <= z || x + z <= y || y + z <= x)
return false;
return true;
}
void solve() {
string s;cin >> s;
vector<int>q;
int cnt = 0;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == '1')cnt++;
else {
if (cnt == 0)continue;
q.push_back(cnt);
cnt = 0;
}
}
q.push_back(cnt);
cnt = 0;
sort(q.begin(), q.end());
for (int i = q.size() - 1; i >= 0; i -= 2)
cnt += q[i];
cout << cnt << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
int t; cin >> t;
while (t--)solve();
}

C. Good Subarrays

题意:

给定一个\(n\)个元素的序列a,求满足\(∑_{i=l}^ra_i=r−l+1\)的区间个数.

#include<bits/stdc++.h>
using namespace std;int T,n;
string s;map<int,int>mp;
int main(){
cin>>T;
while(T--){mp.clear();
cin>>n>>s;mp[0]++;
long long ans=0,sum=0;
for(int i=0;i<n;i++){
sum+=s[i]-'1';
ans+=mp[sum];mp[sum]++;
}
cout<<ans<<endl;
}
}

D. Colored Rectangles

Examples

input

1 1 1
3
5
4

output

20

input

2 1 3
9 5
1
2 8 5

output

99

input

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

output

372

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

数据范围:

\(1≤R,G,B≤200\)

思路

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

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

状态:\(f[i,j,k]\)表示红色用了i个,绿色用了j个,蓝色用了k个的前提下得到的矩形面积总和的最大值.

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

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

出口:所有值的最大值.

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll const int N = 205;
int r[N],g[N],b[N];
int f[N][N][N];
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);
int R,G,B;cin >> R >> G >> B;
for(int i = 1;i <= R;++i) cin >> r[i];sort(r + 1,r + R + 1,greater<int>());
for(int i = 1;i <= G;++i) cin >> g[i];sort(g + 1,g + G + 1,greater<int>());
for(int i = 1;i <= B;++i) cin >> b[i];sort(b + 1,b + B + 1,greater<int>());
int res = 0;
for(int i = 0;i <= R;++i)
{
for(int j = 0;j <= G;++j)
{
for(int k = 0;k <= B;++k)
{
auto& v = f[i][j][k];
if(i >= 1 && j >= 1) v = max(v,f[i - 1][j - 1][k] + r[i] * g[j]);
if(j >= 1 && k >= 1) v = max(v,f[i][j - 1][k - 1] + g[j] * b[k]);
if(i >= 1 && k >= 1) v = max(v,f[i - 1][j][k - 1] + r[i] * b[k]);
res = max(res,v);
}
}
}
cout << res << endl;
return 0;
}

E. Two Types of Spells

Example

input

6
1 5
0 10
1 -5
0 5
1 11
0 -10

output

5
25
10
15
36
21

Educational Codeforces Round 93 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 93 (Rated for Div. 2)题解

    A. Bad Triangle 题目:https://codeforces.com/contest/1398/problem/A 题解:一道计算几何题,只要观察数组的第1,2,n个,判断他们能否构成三 ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  4. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  5. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  9. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  10. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

随机推荐

  1. 2023-11-22:用go语言,给你一个长度为 n 下标从 0 开始的整数数组 nums。 它包含 1 到 n 的所有数字,请你返回上升四元组的数目。 如果一个四元组 (i, j, k, l) 满足

    2023-11-22:用go语言,给你一个长度为 n 下标从 0 开始的整数数组 nums. 它包含 1 到 n 的所有数字,请你返回上升四元组的数目. 如果一个四元组 (i, j, k, l) 满足 ...

  2. python01-基础概念与环境搭建

    学习目标 了解硬件 & 操作系统 & 软件(应用系统)之间的关系. 了解常见的操作系统都有哪些. 了解编译器和解释器的区别和作用. 了解编程语言进行分类 了解Python解释器的种类 ...

  3. Oracle ADG容灾端部署Rman备份的一些实践经验

    随着数据库中数据量的不断增加.业务的复杂性提高.各种政策颁布的系统容灾等级要求,数据库备份的工作及备份文件的有效性及备份文件的管理变得愈发重要.在Oracle数据库中提供了强大的备份和恢复工具,其中R ...

  4. P8594 「KDOI-02」一个仇的复 题解

    我会组合数! 首先发现同一列只有被不同的横块填或被一个相同的竖块填,且用竖块填完1列之后,会分成两个封闭的长方形,而长方形内部则用横块来填充. 先考虑一个子问题,某个 \(2 \times n\) 长 ...

  5. antd Pro组件ProFormList实现自定义action

    antd Pro组件ProFormList实现自定义action ProFormList是ant design pro的结构化数据组件,通常用来实现动态表单. 现在有个需求,除了组件自带的删除和复制, ...

  6. 13 HTTP传输大文件的方法

    目录 如何在有限的带宽下高效快捷传输大文件? 数据压缩 分块传输 范围请求 多段数据 如何在有限的带宽下高效快捷传输大文件? 数据压缩 分块传输 范围请求 多段数据 数据压缩 思路:把大文件整体变小 ...

  7. 解决报错:Java 8 date/time type `java.time.Duration` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling

    1.错误信息: Java 8 date/time type java.time.Duration not supported by default: add Module "com.fast ...

  8. pytorch学习笔记——训练时显存逐渐增加,几个epoch后out-of-memory

    问题起因:笔者想把别人的torch的代码复制到笔者的代码框架下,从而引起的显存爆炸问题 该bug在困扰了笔者三天的情况下,和学长一同解决了该bug,故在此记录这次艰辛的debug之路. 尝试思路1:检 ...

  9. 牛客小白月赛2 F题黑黑白白 (博弈或dfs)

    题目链接:https://www.nowcoder.com/acm/contest/86/F 解题思路:赛后看博客都说是sg函数.emmm,后面看了别人代码dfs也可以,只要找到一条能赢的路就可以. ...

  10. 手动安装pinia、给项目添加pinia实例

    用你喜欢的js包管理器安装pinia: yarn add pinia # 或者使用 npm npm install pinia 创建一个 pinia 实例 (根 store) 并将其传递给应用: 编辑 ...