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题解的更多相关文章

  1. Educational Codeforces Round 61 (Rated for Div. 2) E 多重背包优化

    https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多 ...

  2. Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化

    题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...

  3. Educational Codeforces Round 61 (Rated for Div. 2)

    A. Regular Bracket Sequence 题意:给出四种括号的数量 ((  )) ()  )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个) ...

  4. Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack

    非常经典的dp题,因为1至8的最大公约数是840,任何一个数的和中840的倍数都是可以放在一起算的, 所以我只需要统计840*8的值(每个数字(1-8)的sum%840的总和),剩下都是840的倍数 ...

  5. 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 ...

  6. 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 ...

  7. 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] ...

  8. Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...

  9. 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 ...

随机推荐

  1. 在几份docx文档中里查找某个值

    import docx, os def readDocx(fileName): doc = docx.Document(fileName) content = '\n'.join([para.text ...

  2. spark相关脚本解析

    spark-shell/spark-submit/pyspark等关系如下: #spark-submit 逻辑: ########################################### ...

  3. Mysql-表和字段操作

    1.查看表 show tables; 2.创建表 create table test( id int primary key auto_increment, name varchar(40) not ...

  4. [leetcode-738-Monotone Increasing Digits]

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  5. Thunder团队第六周 - Scrum会议5

    Scrum会议5 小组名称:Thunder 项目名称:i阅app Scrum Master:翟宇豪 工作照片: 胡佑蓉同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblog ...

  6. 软件工程课堂作业(五)——终极版随机产生四则运算题目(C++)

    一.升级要求:让程序能接受用户输入答案,并判定对错.最后给出总共对/错的数量. 二.设计思想: 1.首先输入答案并判断对错.我想到的是定义两个数组,一个存放用户算的结果,另一个存放正确答案.每输出一道 ...

  7. unordered_map(hash_map)和map的比较

    测试代码: #include <iostream> using namespace std; #include <string> #include <windows.h& ...

  8. Swift-重写(Override)

    子类可以为继承来的实例方法(instance method),类方法(class method),实例属性(instance property),或附属脚本(subscript)提供自己定制的实现(i ...

  9. 在Centos中,大容量,且读写频繁的目录

    1./根目录 2./usr目录 3./home目录 4./var目录 5./Swap目录     比较特殊,只要物理内存没使用完,就不会被启用 以上为鸟哥的linuxPDF中的学习心得

  10. [OS] 多线程--第一次亲密接触CreateThread与_beginthreadex本质区别

    转自:http://blog.csdn.net/morewindows/article/details/7421759 本文将带领你与多线程作第一次亲密接触,并深入分析CreateThread与_be ...