Educational Codeforces Round 61 (Rated for Div. 2)
A. Regular Bracket Sequence
题意:给出四种括号的数量 (( )) () )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间)
思路: 条件一:一个或 n个)( 都可以组成 )()()( 这种结构 这只需要 一个((和一个))就可以合成合法的序列
条件二: (( 和))需要相等
()本身就合法不用管
ude<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_startl;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
using namespace std;
const int maxn=;
const int maxm=2e4+;
int main(){
int cnt1,cnt2,cnt3,cnt4;
cin>>cnt1>>cnt2>>cnt3>>cnt4;
if(cnt1==cnt4&&(cnt3&&cnt1||!cnt3)){
printf(""); }
else printf("");
return ;
}
B. Discounts
题意:给出n个数a 和m个数 q 求 选择q个数a 求他们的和-q个数中最小的那个 +剩余的数 的最小值
思路 :直接sort a 求出总和a 然后暴力 每次减去可以删除的那个数即可
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
using namespace std;
const int maxn=3e5+;
typedef long long ll;
ll a[maxn],q[maxn],sum[maxn];
int main(){
int n;
scanf("%d",&n);
FOR(i,,n)scanf("%I64d",&a[i]);
sort(a+,a++n);
FOR(i,,n)sum[i]=sum[i-]+a[i];
int m;
scanf("%d",&m);
int ans=0x3f3f3f3f;
FOR(i,,m-)scanf("%I64d",&q[i]);
FOR(i,,m-){
cout<<sum[n]-sum[n-q[i]+]+sum[n-q[i]]<<endl;;
} return ;
}
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
using namespace std;
const int maxn=+;
typedef long long ll;
pii a[maxn];
int sum[maxn],cnt[maxn];
int main(){
int n,q;
scanf("%d%d",&n,&q);
FOR(i,,q-){
scanf("%d%d",&a[i].F,&a[i].S);
FOR(j,a[i].F,a[i].S)cnt[j]++;
}
// for(int i=1;i<=n;i++)cout<<cnt[i];
int ans=;
FOR(i,,q-){ FOR(j,a[i].F,a[i].S)cnt[j]--;
int tot=;
FOR(k,,n){
tot+=(cnt[k]>);
if(cnt[k]==)sum[k]=;
else sum[k]=;
sum[k]+=sum[k-];
}
// FOR(k,1,n)cout<<sum[k];
// cout<<endl;
int tmp=;
FOR(j,,q-){ if(i==j)continue;
tmp= max(tmp,tot-(sum[a[j].S]-sum[a[j].F-]));
//if(tmp==3)cout<<i<<" "<<j<<" "<<tot<<" "<<sum[a[i].S]<<" "<<sum[a[i].F-1]<<endl;
}
FOR(j,a[i].F,a[i].S)cnt[j]++;
ans=max(tmp,ans);
}
cout<<ans<<endl;
return ;
}
F. Clear the String
题意:祖玛游戏 问最小多少次能全部消掉
思路 :区间dp[i][j] 表示 i 到j全部消掉要多少次 初始化 当s[i]==s[j]时dp[l][j]=dp[l+1][r-1]+1 不能时dp[l][r]=min(dp[l+1][r],dp[l][r-1])+1;然后在l r区间dp[l][r]=min(dp[l][r],dp[l][k]+dp[k][r]-1); 这里k取了两次 所以要减1
#include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
using namespace std;
const int maxn=+;
char s[maxn];
int dp[maxn][maxn]; int main(){
int n;
scanf("%d",&n);
scanf("%s",s+);
FOR(i,,n)dp[i][i]=;
FOR(len,,n){
for(int l=,r=len;r<=n;r++,l++)
{
if(s[l]==s[r])dp[l][r]=dp[l+][r-]+;
else dp[l][r]=min(dp[l+][r],dp[l][r-])+;
FOR(k,l,r){
dp[l][r]=min(dp[l][r],dp[l][k]+dp[k][r]-);
}
}
}
cout<<dp[][n]<<endl; return ;
}
Educational Codeforces Round 61 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
- 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) 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 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- iOS开发简记(5):设备唯一标识与全局变量
这里记录两个iOS开发中经常用到的知识点,一个是唯一标识,一个是全局变量. (1)唯一标识 唯一标识一台设备(比如iPhone.iPad等)是一个基本的实现与业务上的需求,因为这个唯一标识在许多场景都 ...
- Python-类的绑定方法与非绑定方法
类中定义的函数分成两大类 一:绑定方法(绑定给谁,谁来调用就自动将它本身当作第一个参数传入): 绑定到类的方法:用classmethod装饰器装饰的方法. 为类量身定制 类.boud_method() ...
- SDN 实验室学生们
SDN实验室系列:https://edu.cnblogs.com/campus/fzu/SdnLab --研究生及本科生们的博客及GitHub链接.欢迎各位大佬招募. 研究生 2018级 姓名 博客地 ...
- vscode中php断点调试方法!
一.PHP的代码断点调试 1.打开vscode的首选项设置,添加"php.validate.executablePath": "D:\\newXampp\\php\\ph ...
- MyBatis模糊查询不报错但查不出数据的一种解决方案
今天在用MyBatis写一个模糊查询的时候,程序没有报错,但查不出来数据,随即做了一个测试,部分代码如下: @Test public void findByNameTest() throws IOEx ...
- Linux之hosts文件
一.序言: 今天同事部署环境遇到问题, 原因1:修改了主机名,在/etc/hosts文件中加了3台集群的ip和主机名,但是将默认的前两行也改了,没注意看改了哪里, 现象: 1.zookeeper单台可 ...
- JEECG 3.7 Memory Leak
JEECG 3.7 版本常见问题贴 - JEECG官方网站-企业级JAVA快速开发平台 - Powered by Discuz!http://www.jeecg.org/forum.php?mod=v ...
- 二、npm scripts
一.执行原理 安装npm 包,会将其package.json bin 字段添加到node_modules bin 里面,创建对应的.cmd文件,因此: 例如: "scripts": ...
- Setting property 'source' to 'org.eclipse.jst.jee.server:hczm' did not find a matching property
- 给普通用户添加root权限
>>提君博客原创 http://www.cnblogs.com/tijun/ << 第一步,以root用户查看/etc/sudoers [root@ltt2 hadoop] ...