Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training
题目链接:https://codeforces.com/contest/1132/problem/D
题意:
有n台电脑,每台电脑都有初始电量ai,也有一个耗电量bi,意即每1s耗电多少,现在你有一个充电器,它每s可以给一台电脑充x的点亮。
问x最少为多少,可以让所有电脑直至k时刻,点亮都不小于0。
题解:
我们考虑贪心,先给最需要充电的电脑充电,然后二分答案x去检验。大概思路就是这样吧...但是实现起来还是有点困难。
首先处理出每个电脑最晚需要充电的时刻ti,然后每次用一个指针找到第一个需要充电的时刻,不断给这个电脑充电直至这个电脑在下一秒不会没电,然后就更新它的时间。
这个时间复杂度是O(n+k)的,如果用优先队列,代码实现起来就比较简单,但是时间复杂度就多个log,但是cf评测机比较好,还是可以卡过的。
具体细节建议自己去实现一下吧,这样才有更深的体会,代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll n,k;
ll a[N],b[N],c[N];
vector <ll> vec[N];
bool check(ll x){
//x=25;
for(int i=;i<=k;i++) vec[i].clear();
memcpy(c,a,sizeof(a));
for(int i=;i<=n;i++){
ll pos=a[i]/b[i]+;
if(pos<=k){
vec[pos].push_back(i);
c[i]=a[i]%b[i];
}
}
ll last=;
for(int i=;i<=k;i++){
while(last<=k&&vec[last].empty()) last++;
if(last==k+) return true;
if(last<i) return false ;
int now = vec[last].back();
if(c[now]+x<b[now]){
c[now]+=x;
continue ;
}
c[now]+=x;
vec[last].pop_back();
if(last+c[now]/b[now]<=k){
vec[last+c[now]/b[now]].push_back(now);
c[now]%=b[now];
}
}
return true;
}
int main(){
cin>>n>>k;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++) cin>>b[i];
ll l=,r=1e16,mid;
while(l<r){
mid=(l+r)/;
if(check(mid)) r=mid;
else l=mid+;
}
if(l==1e16) cout<<-;
else cout<<r;
return ;
}
F. Clear the String
题目链接:https://codeforces.com/contest/1132/problem/F
题意:
给出一个字符串,每次可以消去相同的连续字符,然后问最少需要几次能将这个字符串全部消去。
题解:
这题主要的关键就是发现无论怎么消,都会和两边的一起消。那么我们就可以类似于区间dp那样通过枚举确定两个边界进行转移了。
枚举中间点的时候,如果发现那个中间点和左端点的字符相同,那么我们就可以将那个中间点和左端点一起消。
反正这个题的解法很多就是了~转移方程也很多。
具体见代码吧:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ,INF = 0x3f3f3f3f3f;
int n;
char s[N];
int dp[N][N];
int main(){
scanf("%d",&n);
scanf("%s",s+);
memset(dp,INF,sizeof(dp));
for(int i=;i<=n;i++) dp[i][i]=;
for(int l=;l<=n;l++){
for(int i=;i<=n;i++){
int j=i+l-;
if(j>n) break ;
for(int k=i;k<j;k++){
if(s[i]==s[j]) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+][j]-);
else dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+][j]);
}
}
}
cout<<dp[][n];
return ;
}
Educational Codeforces Round 61 (Rated for Div. 2) D,F题解的更多相关文章
- Educational Codeforces Round 61 (Rated for Div. 2) E 多重背包优化
https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多 ...
- Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...
- Educational Codeforces Round 61 (Rated for Div. 2)
A. Regular Bracket Sequence 题意:给出四种括号的数量 (( )) () )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个) ...
- Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack
非常经典的dp题,因为1至8的最大公约数是840,任何一个数的和中840的倍数都是可以放在一起算的, 所以我只需要统计840*8的值(每个数字(1-8)的sum%840的总和),剩下都是840的倍数 ...
- Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...
- Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
#include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...
- Educational Codeforces Round 61 (Rated for Div. 2)D(二分,模拟,思维)
#include<bits/stdc++.h>using namespace std;typedef long long ll;int n,k;ll a[200007],b[200007] ...
- Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
随机推荐
- 为什么23种设计模式中没有MVC
GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...
- Python中的eval
Python中的eval方法接受一个字符串参数,并且把字符串里面的内容当成Python代码来执行: eval的缺点是执行速度慢,并且会有安全风险
- Internet History
Alan Turing and Bletchley Park Top secret breaking effort(二战破译希特勒密码) 10,000 people at the peak(team ...
- android 出现Make sure the Cursor is initialized correctly before accessing data from it
Make sure the Cursor is initialized correctly before accessing data from it 详细错误是:java.lang.IllegalS ...
- java---Map接口实现类
Map是一个双列集合接口,如果实现了Map接口,特点是数据以键值对形式存在,键不可重复,值可以重复.java中主要有HashMap.TreeMap.Hashtable.本文主要介绍Map的接口方法: ...
- error LNK2019: 无法解析的外部符号 该符号在函数 中被引用 解决方案
需要添加lib或者dll库.项目-属性-配置属性-链接器-输入-附件依赖项,添加需要的lib. 例如我在运行OSG程序的时候,忘记添加了附件依赖项就会报这个错. 解决方案如图.
- linux的几个发行网站
Red Hat: http://www.redhat.com Fedora: http://fedoraproject.org/ Mandriva: http://www.mandriva ...
- getGeneratedKeys自动获取主键的方法
public class Demo { public static void main(String[] args) { try { String sql="insert into pers ...
- opencv图像像素值读取
说到图像像素,肯定要先认识一下图像中的坐标系长什么样. 1. 坐标体系中的零点坐标为图片的左上角,X轴为图像矩形的上面那条水平线:Y轴为图像矩形左边的那条垂直线.该坐标体系在诸如结构体Mat,Rect ...
- Binding自动侦听
WPF的强大之一就是数据绑定,Binding是数据桥梁,它的两端是分别是源(Source)和目标(Target),一个简单的类的属性值发生变化,会自动反映在UI界面上,这个属性就是Binding的Pa ...