Educational Codeforces Round 93 (Rated for Div. 2)
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)的更多相关文章
- Educational Codeforces Round 93 (Rated for Div. 2)题解
A. Bad Triangle 题目:https://codeforces.com/contest/1398/problem/A 题解:一道计算几何题,只要观察数组的第1,2,n个,判断他们能否构成三 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- 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 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 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 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- 文心一言 VS 讯飞星火 VS chatgpt (143)-- 算法导论12.1 3题
三.用go语言,设计一个执行中序遍历的非递归算法.(提示:一种容易的方法是使用栈作为辅助数据结构;另一种较复杂但比较简洁的做法是不使用栈,但要假设能测试两个指针是否相等.) 文心一言,代码正常运行: ...
- 提升效率,打通万里牛ERP与下游用友U8财务软件的无缝对接
一.对接流程 1.1 销售/售后流程 在万里牛订单出库后,通过轻易云数据集成平台将数据推送至用友U8销售订单和销售出库单,这些单据可以进行关联操作. 当万里牛售后单完成退货入库后,通过数据集成平台将数 ...
- Java八股面试题整理(1)
1.为什么Java代码可以实现一次编写,到处运行? 参考答案 JVM(Java虚拟机)是Java跨平台的关键. 在程序运行前,Java源代码(.java)需要经过编译器编译成字节码(.class).在 ...
- 2023-12-13:用go语言,密码是一串长度为n的小写字母,一则关于密码的线索纸条, 首先将字母a到z编号为0到25编号, 纸条上共有n个整数ai,其中a1表示密码里第一个字母的编号, 若i>1的
2023-12-13:用go语言,密码是一串长度为n的小写字母,一则关于密码的线索纸条, 首先将字母a到z编号为0到25编号, 纸条上共有n个整数ai,其中a1表示密码里第一个字母的编号, 若i> ...
- leetcode:354 俄罗斯套娃信封问题(LIS)
解题思路: 根据题意,不难发现组合的元素,他们的长宽都是单调递增的,因此可以转化为最长上升子序列问题. 首先按照长度从小到大对信封进行排序,长度相同,按照宽度从大到小进行排序.因为当长度相同,因为可能 ...
- pinia状态管理初识
一款官方推荐的,代替vuex的,新的状态管理工具. 官方网: https://pinia.vuejs.org/zh/introduction.html 主要区别: 去除了modules的概念,每个st ...
- Flask-SQLAlchemy常用新旧查询语法对比
https://docs.sqlalchemy.org/en/20/tutorial/data.html 新旧版语法的说明 在2.x的SQLALchemy中,查询语法为: db.session.exe ...
- python 解析网址信息
python 解析网址信息 本篇文章主要讲述python 中如何解析一个url的信息. 1: requests获取网页信息 #!/usr/bin/python3 # -*- coding: UTF-8 ...
- vulntarget-c-wp
vulntarget-c 信息收集 扫开的端口有web服务 访问了web页面,发现用的是laravel框架 搜索一下历史漏洞,在gayhub上找到这个可以用,能够执行简单命令 python3 expl ...
- 善用 vscode 的批量和模板技巧来提效
vs code 其实有很多实用的技巧可以在日常工作中带来很大的提效,但可能是开发中没有相应的痛点场景,因此有些技巧接触的人不多 本篇就来介绍下多光标的批量操作和模板代码两种技巧在日常工作中的提效 涉及 ...