Educational Codeforces Round 93 (Rated for Div. 2)题解
A. Bad Triangle
题目:https://codeforces.com/contest/1398/problem/A
题解:一道计算几何题,只要观察数组的第1,2,n个,判断他们能否构成三角形即可。
必须注意:从反方向判断时要注意:两边之和大于第三边的反向是:a[1]+a[2]<=a[n]一定注意为小于等于,两边之差小于第三边的反义是:a[n]-a[2]>=a[1]切记注意是大于等于
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
ll t,n;
ll a[N];
int main()
{
ll i,j,k;
cin>>t;
while(t--)
{
bool flag=true;
cin>>n;
for(i=;i<=n;i++)
cin>>a[i];
if(a[]+a[]<=a[n]||a[n]-a[]>=a[])
cout<<"1 2 "<<n<<endl;
else
cout<<"-1"<<endl;
}
return ;
}
B. Substring Removal Game
题目:https://codeforces.com/contest/1398/problem/B
题解:一到关于字符串的贪心问题,由于我们要1的个数最大,所以只要找相邻的1的个数就好,存到数组后进行排序,由于我们是先手,因此每隔一个取一次。
代码:
#include<bits/stdc++.h>
using namespace std;
int a[];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int i,t;
string s;
cin>>t;
while(t--)
{
cin>>s;
int len=s.length();
int k=;
int j=;
for(i=;i<len;i++)
{
if(s[i]=='')
k++;
else
{
if(k!=)
{
a[j++]=k;
k=;
}
}
}
if(k!=)
a[j++]=k;
int ans=;
sort(a,a+j,cmp);
for(i=;i<j;i++)
{
if(i%==)
ans+=a[i];
}
cout<<ans<<endl;
}
return ;
}
C. Good Subarrays
题目:https://codeforces.com/contest/1398/problem/C
题解:我认为这道题是最难想的,一开始用暴力,TLE在第三组数据。因而不能用这种方法。
在线处理的方法。
我们想想,用子数组总和减去元素个数,如果是为0,那么就是好子数组,如果好子数组中又包含好子数组呢?那么该好子数组是不是可以分为三个好子数组。
如果不为0呢?那么我们是不是可以记录这个状态,我们继续往后探索的的时候突然发现子数组总和减去元素个数又为我们上次记录过的状态。那么这个子数组是不是可以拆成我们上次记录过的状态子数组和另一个子数组减元素个数为0的好子数组?(仔细思考这里,非常重要!)
那么我们层层深入,如果一个子数组能这样分为我们已经访问过的状态子数组和一个好子数组,那么不就实现在线处理了吗?因为现在我们只要遍历一遍数组了,其他的子数组我们就可以利用当前已经记录的子数组分解获得。那么时间复杂度就大大减小了。
那么我们怎么记录之前状态呢?这里就要使用map容器了,我们标记所有计算的差值状态,利用ans统计值即可。若之前标记过两次,说明我们可以拆成两种情况:一个差值为标记过的子数组和一个好子数组
代码:
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************// int main()
{
IOS;
int t,n,i,j;
string str;
cin>>t;
while(t--)
{
cin>>n;
cin>>str;
ll ans=,num=;
map<int,ll>mp;
mp[]=;//当差值为0时就是一个好数组
rep(i,,n-)
{
num+=str[i]-'';//计算前缀和数组
ans+=mp[num-(i+)];//加上当前的状态对应的值
mp[num-(i+)]++;//记录上标记一次
//其实好与坏的区别就在于第一个是好还是坏
}
cout<<ans<<endl;
}
return ;
}
D. Colored Rectangles
题目:https://codeforces.com/contest/1398/problem/D
题解:DP题,我们来思考一下他们的状态转移,设我们可以构造的最大矩形数为nnn,(注意:最大矩形数是一定固定的)那么该状态的最优解是不是可以转换为矩形数为n−1n-1n−1的最优解+当前可构建矩形面积的最大值。我们用dp[i][j][k]表示用去了i个R颜色彩棒,j个G个颜色彩棒,k个C颜色彩棒,那么我们表示矩形数为n−1自然对应的彩棒数要减2了,这里注意有三种情况都要判断
需要注意的是必须对其进行排序,因为我们相当于是不断加入三根彩棒,比较当时拥有的彩棒合成矩形最大值,这就是一个矩形的最优解,再往后推,逐渐得到总矩形的最优解
代码:
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大
const int maxn = ;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii; ll dp[maxn][maxn][maxn];
int r[maxn],g[maxn],b[maxn];
int main()
{
IOS;
int R,G,B,i,j,k;
cin>>R>>G>>B;
rep(i,,R-)
cin>>r[i];
rep(i,,G-)
cin>>g[i];
rep(i,,B-)
cin>>b[i];
//排序
sort(r,r+R);
sort(g,g+G);
sort(b,b+B);
rep(i,,R)
{
rep(j,,G)
{
rep(k,,B)
{
if(i&&j)
dp[i][j][k]=max(dp[i][j][k],dp[i-][j-][k]+r[i-]*g[j-]);
if(i&&k)
dp[i][j][k]=max(dp[i][j][k],dp[i-][j][k-]+r[i-]*b[k-]);
if(j&&k)
dp[i][j][k]=max(dp[i][j][k],dp[i][j-][k-]+g[j-]*b[k-]);
}
}
}
cout<<dp[R][G][B]<<endl;
return ;
}
Educational Codeforces Round 93 (Rated for Div. 2)题解的更多相关文章
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 47 (Rated for Div. 2) 题解
题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ...
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
A.每个状态只有一种后续转移,判断每次转移是否都合法即可. #include <iostream> #include <cstdio> using namespace std; ...
- Educational Codeforces Round 78 (Rated for Div. 2) 题解
Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...
- Educational Codeforces Round 81 (Rated for Div. 2) 题解
过了n天补的题解:D AB就不用说了 C. Obtain The String 思路挺简单的,就是贪心,但是直接贪心的复杂度是O(|s|*|t|),会超时,所以需要用到序列自动机 虽然名字很高端但是就 ...
随机推荐
- 搭建kubernetes集群
什么是Kubernetes? Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展.如果你曾经用过Docker容器技术部署容器,那么可以将Docker看成K ...
- 设计模式:memento模式
目的:在不破坏系统封装性的前提下,记录系统每一步的状态,可以做到状态回退和前进 方法: 定义一个数据类,保存所有相关数据 定义一个管理类,提供保存和恢复的接口 具体操作类调用管理类的保存和恢复接口 例 ...
- twitch游戏直播(【国外】平台)如何绑定二次验证码_虚拟MFA?
一般点账户名——设置——安全设置中开通虚拟MFA两步验证 具体步骤见链接 twitch游戏直播([国外]平台)如何绑定二次验证码_虚拟MFA? 二次验证码小程序于谷歌身份验证器APP的优势(更多见官网 ...
- grpc 之 word2pdf使用
做一个word转pdf的服务,采用grpc,使用libreoffice命令. 1.构建libreoffice镜像 FROM python:3.6 ENV TZ=Asia/Shanghai RUN ...
- jmeter接口测试 -- 设置跨线程组的全局变量
一.操作步骤 1.先提取被设置的变量 2.再用 [线程组] - [后置处理] - [BeanShell PostProcessor]来设置跨线程的全局变量:${__setProperty(新变量名,$ ...
- 让你的GitHub下载飞速提升到2M/s以上
2020年7月27日整理发布多种GitHub加速方式! 转载自:https://code.pingbook.top/blog/2020/How-To-Speed-Github.html 1. GitH ...
- Django学习路37_request属性
打印元信息,基本上都会打印出来 类字典结构的 key 键 允许重复 get 请求可以传参,但是长度有限制 最大不能超过 2K post 文件上传使用 get 参数 默认放在网址中 post 在 ...
- Python decode()方法
描述 Python decode() 方法以 encoding 指定的编码格式解码字符串.默认编码为字符串编码.高佣联盟 www.cgewang.com 语法 decode()方法语法: str.de ...
- PHP password_needs_rehash() 函数
password_hash() 函数用于检测散列值是否匹配指定的选项. PHP 版本要求: PHP 5 >= 5.5.0, PHP 7高佣联盟 www.cgewang.com 语法 bool p ...
- Prism.Interactivity 和 Prism.Modularity 介绍
Prism.Interactivity: 主要用来截取View即界面的一些处理,而这些功能通过vm 不好实现,只能用 CommandBehaviorBase 来截取处理,特别是在处理界面异常很有用. ...