Educational Codeforces Round 97 (Rated for Div. 2)
补了一场Edu round。
A : Marketing Scheme
水题
#include <cstdio>
#include <algorithm>
typedef long long ll;
int T,l,r; template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
int main(){
read(T);
while(T--){
read(l); read(r);
if(l * 2 > r) printf("YES\n");
else printf("NO\n");
}
return 0;
}
B :Reverse Binary Strings
水构造
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int M = 200010;
int T,n,cnt1,cnt2;
int a[M]; template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
int main(){
read(T);
while(T--){
read(n); cnt1 = cnt2 = 0;
for(int i = 1;i <= n; i++){
char ch = getchar();
for(;ch != '0' && ch != '1'; ch = getchar()) ;
a[i] = ch - '0';
if(i != 1){
if(a[i] == a[i - 1] && a[i] == 1) cnt1++;
else if(a[i] == a[i - 1] && a[i] == 0) cnt2++;
}
}
printf("%d\n",std::max(cnt1,cnt2));
}
return 0;
}
C : Chef Monocarp
比较奇怪的背包,照理压成一维。
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
typedef long long ll;
const int M = 210;
int T,n;
int t[M], dp[M]; template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
int main(){
read(T);
while(T--){
read(n);
for(int i = 1;i <= n; i++) read(t[i]);
std::sort(t + 1,t + n + 1);
memset(dp,0x3f,sizeof(dp));
dp[0] = 0;
for(int i = 1;i <= n << 1; i++)
for(int j = n;j >= 1; j--)
dp[j] = std::min(dp[j],dp[j - 1] + abs(i - t[j]));
printf("%d\n",dp[n]);
}
return 0;
}
D :Minimal Height Tree
因为是bfs,所以直接按照性质模拟即可。
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int M = 200010;
int T,n;
int a[M]; template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
int main(){
read(T);
while(T--){
read(n);
for(int i = 1;i <= n; i++) read(a[i]);
int dep = 0, cur = 0, sum = 1;
for(int i = 2,j;i <= n; i++){
if(!cur){
cur = sum; dep++;
}
cur--; j = i;
while(j <= n){
if(a[j] < a[j + 1]){
j++; sum++;
}
else break;
}
i = j;
}
printf("%d\n",dep);
}
return 0;
}
E :Make It Increasing
贪心。直接在每个被b圈定的区间内贪心,记录不需要更改的点个数。
还有一个明显的转化,具体见代码。
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int M = 500010;
int n,k,ans;
int a[M], b[M]; template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
int sta[M], top = 0;
int main(){
read(n); read(k);
for(int i = 1;i <= n; i++)
read(a[i]), a[i] -= i;
for(int i = 1;i <= k; i++) read(b[i]);
a[n + 1] = 1e9; a[0] = -1e9;
b[k + 1] = n + 1;
for(int i = 0,l,r;i <= k; i++){
l = b[i]; r = b[i + 1];
if(a[l] > a[r]){
printf("-1\n"); return 0;
}
top = 0;
for(int j = l + 1;j < r; j++)
if(a[l] <= a[j] && a[j] <= a[r]){
int it = std::upper_bound(sta + 1,sta + top + 1,a[j]) - sta;
if(it == top + 1) sta[++top] = a[j];
else sta[it] = a[j];
}
ans += r - l - 1 - top;
}
printf("%d\n",ans);
return 0;
}
F :Emotional Fishermen
既然是记录方案数,那应该是dp了。具体见代码,注意特判。
#include <cstdio>
#include <algorithm>
typedef long long ll;
const int M = 5010, mod = 998244353;
int n;
int a[M], pre[M];//表示最大的j使得a[j] * 2 <= a[i]
int dp[M];//表示以i点为最大值的方案数 template <typename T>
inline void read(T &x){
x = 0; char ch = getchar(); int f = 1;
for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
x *= f;
}
inline ll q_pow(ll x,ll num){
ll ret = 1;
for(;num; num >>= 1){
if(num & 1) ret = (1ll * ret * x) % mod;
x = (1ll * x * x) % mod;
}
return ret;
}
int fac[M], ifac[M];
inline void pre_work(){
fac[0] = fac[1] = ifac[0] = 1;
for(int i = 2;i <= n; i++) fac[i] = (1ll * fac[i - 1] * i) % mod;
ifac[n] = q_pow(fac[n],mod - 2);
for(int i = n - 1;i >= 1; i--) ifac[i] = (1ll * ifac[i + 1] * (i + 1)) % mod;
}
inline int A(int i,int j){
if(i > j || i < 0 || j < 0) return 0;
return (1ll * fac[j] * ifac[j - i]) % mod;
}
int main(){
read(n);
for(int i = 1;i <= n; i++) read(a[i]);
std::sort(a + 1,a + n + 1);
int l = 0;
for(int i = 1;i <= n; i++){
while(a[l + 1] << 1 <= a[i]) l++;
pre[i] = l;
}
if(pre[n] != n - 1){
printf("0\n"); return 0;
}
dp[0] = 1; pre[0] = -1;
pre_work();
for(int i = 1;i <= n; i++)
for(int j = 0;j <= pre[i]; j++)
dp[i] = (1ll * dp[i] + 1ll * dp[j] * A(pre[i] - pre[j] - 1,n - pre[j] - 2) % mod) % mod;
printf("%d\n",dp[n]);
return 0;
}
G :Death DBMS
后缀自动机,不会。
Educational Codeforces Round 97 (Rated for Div. 2)的更多相关文章
- Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)
题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...
- Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...
- Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)
题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...
- Educational Codeforces Round 97 (Rated for Div. 2) C. Chef Monocarp (DP)
题意:有\(n\)个菜在烤箱中,每个时刻只能将一个菜从烤箱中拿出来,第\(i\)个时刻拿出来的贡献是\(|i-a[i]|\),你可以在任意时刻把菜拿出来,问将所有菜拿出的最小贡献是多少? 题解: 先对 ...
- 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 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
随机推荐
- Magicodes.IE之导入导出筛选器
总体设计 Magicodes.IE是一个导入导出通用库,支持Dto导入导出以及动态导出,支持Excel.Word.Pdf.Csv和Html.在本篇教程,笔者将讲述如何使用Magicodes.IE的 ...
- Spring AOP系列(二) — 动态代理引言
接上一篇Spring AOP系列(一)- 代理模式,本篇来聊聊动态代理. 动态代理与静态代理的区别 要想了解动态代理与静态代理的区别,需要有两个前置知识点:java程序是如何执行的以及类加载机制. j ...
- 2020HC大会上,这群人在讨论云原生…
启程 一年一度的华为全联接大会又开启了,伴随着一封来自华为全联接大会的邀请函,我来到了2020华为全联接大会的现场. 理解 今年,华为全联接大会的主题是:共 创 行 业 新 价 值!(NEW VALU ...
- HTML中css水平居中的几种方式
1. 子元素为行内元素时,父元素使用 text-align: center; 实现子元素的水平居中: 2. 子元素为块级元素时, 2.1. 将子元素设置 margin: 0 auto; 实现居中: 2 ...
- Oracle缓存表与Oracle缓存的区别
一.Oracle缓存表 与 Oracle缓存 的概念 Oracle 缓存:是把Oracle近期查询的语句放置在Oracle设定的缓存当中. Oracle 缓存表:是把某个表放置在缓存当中,缓存是Ora ...
- 为了省钱,我用1天时间把PHP学了!
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 你在通往架构师的路上吗? 程序员这个行业就像是在不断的打怪升级,突破每一阶段的瓶颈期 ...
- 警惕char类型直接相加
今天在写某个程序需要对两个数字字符串进行相加操作,比如字符串1:12345,字符串2:23456.需要1和2相加.2和3相加.就是两个字符相同位置的数进行相加. 这个一看很好完成,写一个for,然后取 ...
- java安全编码指南之:锁的双重检测
目录 简介 单例模式的延迟加载 double check模式 静态域的实现 ThreadLocal版本 简介 双重检测锁定模式是一种设计模式,我们通过首次检测锁定条件而不是实际获得锁从而减少获取锁的开 ...
- GIT之分支管理
分支管理 一.分支推进 主分支 单线分支,随着代码的提交而形成的一条直线,HEAD 随着commit提交之后的节点移动而移动. 子分支 当切换到子分支的时候,HEAD 则指向子分支的节点. 在子分支上 ...
- day01 Pyhton学习
一.python介绍 python是一种解释型.弱类型的高级编程语言. 编译型:是把源程序的每一条语言编译成机器语言,并保存成二进制文件,给计算机执行,运算速度快. 优点:程序执行效率高,可以脱离语言 ...