A .Regular Bracket Sequence

题意:给定“((” , “()” ,  “)(”,  “))”四种,问是否可以组成合法括号匹配

思路:设四种是ABCD,B可以不用管,而C在A或者D存在时可以不考虑,然后就是A=D。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
ll A,B,C,D,ans;
int main()
{
scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
ans=B;
if(A||D) ans+=C; ans+=2LL*min(A,D);
if(ans==A+B+C+D) puts("");
else puts("");
return ;
}

B .Discounts

题意:给定N个物品,Q次询问,每次询问给定P,表示你可以选P个,最便宜的那个不用付款,问最少付款额。

思路:排序,贪心。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
ll a[maxn],sum,ans;
int main()
{
int N,M,x; scanf("%d",&N);
rep(i,,N) scanf("%lld",&a[i]),sum+=a[i];
sort(a+,a+N+);
scanf("%d",&M);
rep(i,,M) {
scanf("%d",&x);
printf("%lld ",sum-a[N+-x]);
}
return ;
}

C .Painting the Fence

题意:给定长度为N个点,M条线段,问选择M-2条,最多可以覆盖多少个点(N,M<5000)

思路:首先如果点被覆盖数大于2,不用考虑了,一定被覆盖。所以先求出被1个线段覆盖的,被2覆盖的,然后枚举不选的线段,前缀和更新答案即可。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
int sum[maxn],num[][maxn],ans,tot; pair<int,int>s[maxn];
int main()
{
int N,M;
scanf("%d%d",&N,&M);
rep(i,,M){
scanf("%d%d",&s[i].first,&s[i].second);
sum[s[i].first]++; sum[s[i].second+]--;
}
rep(i,,N) sum[i]+=sum[i-];
rep(i,,N){
if(sum[i]) tot++;
num[][i]+=num[][i-];
num[][i]+=num[][i-];
if(sum[i]==) num[][i]++;
if(sum[i]==) num[][i]++;
}
sort(s+,s+M+);
rep(i,,M)
rep(j,i+,M){
if(s[j].first>s[i].second) ans=max(ans,tot-(num[][s[i].second]-num[][s[i].first-])-(num[][s[j].second]-num[][s[j].
first-]));
else if(s[j].second<=s[i].second)
ans=max(ans,tot-(num[][s[j].first-]-num[][s[i].first-])-(num[][s[i].second]-num[][s[j].second])-(num[][s
[j].second]-num[][s[j].first-]));
else
ans=max(ans,tot-(num[][s[j].first-]-num[][s[i].first-])-(num[][s[j].second]-num[][s[i].second])-(num
[][s[i].second]-num[][s[j].first-]));
}
printf("%d\n",ans);
return ;
}

D .Stressful Training

题意:有N台电脑,每台电脑初始电量a[],每单位时间掉电b[],现在给一个充电器,这个充电器同一单位时间只能给一个电脑充电,问每单位时间至少充多少,满足每台电脑都至少坚持K时间。

思路:二分X,二分之后这么写呢,是线性的呢。 求出每个人最晚的一些充电时间,然后总量不大于K,然后就是线性的向前摊平,如果同一时间个数大于1,则false。

这两个限制使得每次二分是线性的。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
ll a[maxn],b[maxn],ans=-;int N,K,vis[maxn];
bool check(ll x)
{
int cnt=; rep(i,,K) vis[i]=;
rep(i,,N){
ll L=a[i];
while(L-b[i]*(K-)<){
int t=L/b[i]+;
if(L/b[i]+<=K) vis[L/b[i]+]++;
cnt++; if(cnt==K) return false;
L+=x;
}
}
for(int i=K;i>;i--) {
if(vis[i]) vis[i-]+=vis[i]-;
}
if(vis[]>) return false;
return true;
}
int main()
{
ll L=,R=1e18,Mid;
scanf("%d%d",&N,&K);
rep(i,,N) scanf("%lld",&a[i]);
rep(i,,N) scanf("%lld",&b[i]);
while(L<=R){
Mid=(L+R)/;
if(check(Mid)) R=Mid-,ans=Mid;
else L=Mid+;
}
printf("%lld\n",ans);
return ;
}

E .Knapsack

题意:给定8种物体的个数a[],重量分别对应1到8,给定W,问选处的不超过W的最大重量。 (W<1e18,a<1e16)

思路:二进制拆分物体,然后暴力背包,可能会空间爆炸,用ans减去没用的一些空间就够了。

这样的话,物体要从大到小排序,这样才能保证map的空间,以及减枝效果。

(这是比较暴力的做法了,有更优美的解法

#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,bool>mp,tmp;
map<ll,bool>::iterator it;
const int maxn=;
ll ans,W,a[maxn],v[maxn],sum[maxn]; int tot,cnt;
int main()
{
scanf("%lld",&W);
for(int i=;i<=;i++){
scanf("%lld",&a[i]);
if(!a[i]) continue; cnt++; ll t=;
ans=max(ans,min(W/i,a[i])*i);
while(){
tot++; v[tot]=min(t,a[i])*i;
a[i]-=min(t,a[i]); t=t*;
if(!a[i]) break;
}
}
if(cnt==){
printf("%lld\n",ans); return ;
}
sort(v+,v+tot+); reverse(v+,v+tot+);
for(int i=tot;i>=;i--) sum[i]=sum[i+]+v[i];
mp[]=true;
for(int i=;i<=tot;i++){
tmp.clear();
for(it=mp.begin();it!=mp.end();it++){
ll x=it->first;
tmp[x]=true;
if(x+v[i]<=W) tmp[x+v[i]]=true;
}
mp.clear();
for(it=tmp.begin();it!=tmp.end();it++){
if(it->first+sum[i+]<ans) continue;
mp[it->first]=true;
ans=max(it->first,ans);
}
}
printf("%lld\n",ans);
return ;
}

F .Clear the String

题意:给定长度为N的字符串,每次可以删去一段连续的相同字符,求最小删去次数。(N<500)

思路:区间DP,反过来就是“刷墙”这种题:每次可以刷一段,问最少刷的次数。 如果col[L]=col[R],我们可以先刷[L,R],然后去刷[L+1,R-1];如果中间有相同的,还可以分子区间。所以是个需要枚举中间点的O(N^3)区间DP。(比赛的时候想N^2做,WA了。

#include<bits/stdc++.h>
#define ll long long
#define rep(i,w,v) for(int i=w;i<=v;i++)
using namespace std;
const int maxn=;
int dp[maxn][maxn]; char a[maxn];
int main()
{
int N,tot=; scanf("%d%s",&N,a+);
rep(i,,N){
if(a[i]!=a[i-]) a[++tot]=a[i];
}
N=tot;
memset(dp,0x3f,sizeof(dp));
rep(len,,N){
rep(L,,N-len+){
int R=L+len-;
if(len==) dp[L][R]=;
else if(len==) dp[L][R]=(a[L]==a[R]?:);
else {
dp[L][R]=len;
if(a[L]==a[R]) dp[L][R]=min(dp[L+][R],dp[L][R-]);
else{ dp[L][R]=min(dp[L+][R],dp[L][R-])+;
rep(k,L,R) dp[L][R]=min(dp[L][R],dp[L][k]+dp[k][R]-);
}
}
}
}
printf("%d\n",dp[][N]);
return ;
}

CF1132.Educational Codeforces Round 61(简单题解)的更多相关文章

  1. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  2. Educational Codeforces Round 61

    Educational Codeforces Round 61 今早刚刚说我适合打pikmike出的EDU 然后我就挂了 A 不管 B 不管 C 这道题到快结束了才调出来 大概就是\(n^2\)枚举不 ...

  3. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  4. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  5. Educational Codeforces Round 61 (Rated for Div. 2) D,F题解

    D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...

  6. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  7. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  8. Educational Codeforces Round 61 C 枚举 + 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

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

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

随机推荐

  1. 小程序 wepy wx.createAnimation 向右滑动渐入渐出

    <style lang="less"> .animation { width: 100vw; height: 100vh; opacity: 0; background ...

  2. nyoj-0708-ones(dp)

    nyoj-0708-ones 题意:用1,+,*,(,). 这四个符号组成表达式表达数s(0 <= s <= 10000),且1最少时1的的个数 状态转移方程: dp[i] = min(d ...

  3. Win10系列:JavaScript页面导航

    页面导航是在开发应用的过程中使用频率较高的技术,其中比较常用的导航方式有多页导航和页内导航,采用多页导航方式的应用程序包含一系列的页面,在一个页面中加入另一个页面的链接地址后,单击链接将跳转到指定页面 ...

  4. js作用域及闭包

    作用域 执行环境是js最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为. 1.全局执行环境就是最外围的一个执行环境,每一个函数都有自己的作用域 2.简单的说局部作用 ...

  5. oracle servicename 与SID的区别

    http://blog.csdn.net/z69183787/article/details/25706269

  6. Mysql 实列结构-进程

    一.MySQL后台进程简介 master thread与四大I/O线程:read thread.write thread.redo log thread.change buffer thread与 p ...

  7. HTML中元素的position属性详解

    HTML中元素的position属性详解 转载自:https://blog.csdn.net/wangzunkuan/article/details/81540935   HTML中DOM元素有5种定 ...

  8. 初始JSP

    什么是JSP 1.JSP(Java Server Pages):在HTML中嵌入Java脚本代码 静态内容是JSP页面中的静态文本,其基本是HTML文本,与Java和JSP语法无关. 例子: 运行结果 ...

  9. Android : 网络adb配置及有线端口占用解决方法

    一.调试环境: Android Debug Bridge version 1.0.40: Nexus6P平板(Android 8.0系统): 二.网络ADB调试: 1. Android设备除了用有线u ...

  10. datatabale 服务器分页

    转载:http://blog.csdn.net/angelvyvyan/article/details/51783272$(document).ready( function() { $('#tabl ...