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|),会超时,所以需要用到序列自动机 虽然名字很高端但是就 ...
随机推荐
- Windows File Recovery - 微软官方文件恢复工具
假如你不小心误删除了文件或因各种意外情况丢失数据后,你可以通过 微软这款工具 这个工具来尝试恢复它们.WinFR 工具支持读取本机硬盘.移动硬盘.U 盘,或者连接相机.手机.使用读卡器来恢复 SD.T ...
- MapReduce之自定义分区器Partitioner
@ 目录 问题引出 默认Partitioner分区 自定义Partitioner步骤 Partition分区案例实操 分区总结 问题引出 要求将统计结果按照条件输出到不同文件中(分区). 比如:将统计 ...
- python golang中grpc 使用示例代码详解
python 1.使用前准备,安装这三个库 pip install grpcio pip install protobuf pip install grpcio_tools 2.建立一个proto文件 ...
- 干货分享丨玩转物联网IoTDA服务系列五-智能家居煤气检测联动
摘要:该场景主要描述的是设备可以通过LWM2M协议与物联网平台进行交互,用户可以在控制台或通过应用侧接口创建设备联动规则,把设备上报的属性转发,通过物联网平台规则引擎转变成命令下发给其他指定设备. 场 ...
- python 结合redis 队列 做一个例子
结合redis 队列 做了一个例子 #!/usr/bin/env python # coding: utf-8 # @Time : 2018/12/21 0021 13:57 # @Site : # ...
- vue学习(十五) 过滤器简单实用
vue过滤器: 概念:vue.js允许你自定义过滤器可被用作一些常见文本的格式化.过滤器可以用在两个地方:插值表达式 v-bind表达式 由管道符指示 //过滤器调用时候的格式 {{ name ...
- Kubernetes/K8s CKA认证全套实训视频教程下载
地址: 链接:https://pan.baidu.com/s/1bwEUZTCVzqM3mGjrlISbcg 提取码:r1kx 目录: 目录: │ 1-1.kubernetes理论教程 - 云原生技术 ...
- MacOS IDEA下SVN配置与使用
第一部分,准备工作 到IDEA的配置下设置SVN命令,一般来说,IDEA已经设置好了,如果没有自己找到存放SVN命令的目录,将SVN配置进去,命令应该存放在/Library/Developer/Com ...
- 国内安装Homebrew
原文链接更详细 命令 $ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew. ...
- Python List min()方法
描述 min() 方法返回列表元素中的最小值.高佣联盟 www.cgewang.com 语法 min()方法语法: min(list) 参数 list -- 要返回最小值的列表. 返回值 返回列表元素 ...