A.Raise Both Hands \(\texttt{Diff }11\)

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define void inline void
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define test(i) cout<<"test: "<<i<<endl
#define testp(i,j) cout<<i<<" "<<j<<endl
#define testd(i) cout<<i<<" "
#define end cout<<"\n"
#define div <<" "<<
#else
#define test(i)
#define testp(i,j)
#define testd(i)
#define end false
#define div ,
#endif
template<typename T>
void read(T& x){
x=0;bool sym=0;char c=getchar();
while(!isdigit(c)){sym^=(c=='-');c=getchar();}
while(isdigit(c)){x=x*10+c-48;c=getchar();}
if(sym)x=-x;
}
template<typename T,typename... Args>
void read(T& x,Args&... args){
read(x);read(args...);
}
int main(){
int l,r;
cin>>l>>r;
if(l==1 and r!=1){
cout<<"Yes";
}
else if(l!=1 and r==1){
cout<<"No";
}
else{
cout<<"Invalid";
}
}

B.Binary Alchemy \(\texttt{Diff }84\)

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define void inline void
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define test(i) cout<<"test: "<<i<<endl
#define testp(i,j) cout<<i<<" "<<j<<endl
#define testd(i) cout<<i<<" "
#define end cout<<"\n"
#define div <<" "<<
#else
#define test(i)
#define testp(i,j)
#define testd(i)
#define end false
#define div ,
#endif
template<typename T>
void read(T& x){
x=0;bool sym=0;char c=getchar();
while(!isdigit(c)){sym^=(c=='-');c=getchar();}
while(isdigit(c)){x=x*10+c-48;c=getchar();}
if(sym)x=-x;
}
template<typename T,typename... Args>
void read(T& x,Args&... args){
read(x);read(args...);
}
int n;
int a[101][101];
int main(){
cin>>n;
for(int i=1;i<=n;++i){
for(int j=1;j<=i;++j){
cin>>a[i][j];
}
}
int st=1;
for(int i=1;i<=n;++i){
if(st>=i){
st=a[st][i];
}
else{
st=a[i][st];
}
}
cout<<st<<endl; }

C.Word Ladder \(\texttt{Diff }228\)

给你两个字符串 \(S,T\),长度相等,要求你每次改变 \(S\) 一个字符,最后令 \(S=T\),要求在过程中的每一步都使 \(S\) 字典序尽可能最小,输出过程

考虑到当 \(S_{i}\lt T_{i}\) 的时候应该最先改,否则应该最后改. 因此正着遍历一遍跑出 \(S_{i}\lt T_{i}\) 的,剩下的倒着跑出来即可.

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define void inline void
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define test(i) cout<<"test: "<<i<<endl
#define testp(i,j) cout<<i<<" "<<j<<endl
#define testd(i) cout<<i<<" "
#define end cout<<"\n"
#define div <<" "<<
#else
#define test(i)
#define testp(i,j)
#define testd(i)
#define end false
#define div ,
#endif
template<typename T>
void read(T& x){
x=0;bool sym=0;char c=getchar();
while(!isdigit(c)){sym^=(c=='-');c=getchar();}
while(isdigit(c)){x=x*10+c-48;c=getchar();}
if(sym)x=-x;
}
template<typename T,typename... Args>
void read(T& x,Args&... args){
read(x);read(args...);
}
string s,t;
vector<string>ss;
int main(){
cin>>s>>t;
while(s!=t){
for(int i=0;i<=s.length()-1;++i){
if(s[i]>t[i]){
s[i]=t[i];
ss.push_back(s);
}
}
for(int i=s.length()-1;i>=0;--i){
if(s[i]<t[i]){
s[i]=t[i];
ss.push_back(s);
}
}
}
cout<<ss.size()<<endl;
for(string i:ss) cout<<i<<endl;
}

D.Cross Explosion \(\texttt{Diff }1088\)

给定 \(H\times W\) 的矩阵,初始全是墙,\(Q\) 次询问,每次给出一个坐标 \((x,y)\) 进行如下操作:

  • 若 \((x,y)\) 是墙,直接摧毁
  • 否则,摧毁 \((x,y)\) 在上下左右四个方向上距离最近的墙,该方向上没有墙则不摧毁

求最终的墙数

\(H\times W\le 4\times 10^{5},Q\le 2\times 10^{5}\)

考察对 STL 的用法

考虑对横行和数列分别建 set,记录当前行/列存在墙的坐标,每次删除的时候,只需要进入对应行/列的 set 直接查找删除即可

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define void inline void
#define ONLINE_JUDGE
//#ifndef ONLINE_JUDGE
//#define test(i) cout<<"test: "<<i<<endl
//#define testp(i,j) cout<<i<<" "<<j<<endl
//#define testd(i) cout<<i<<" "
//#define div <<" "<<
//#else
//#define test(i)
//#define testp(i,j)
//#define testd(i)
//#define end false
//#define div ,
//#endif
template<typename T>
void read(T& x){
x=0;bool sym=0;char c=getchar();
while(!isdigit(c)){sym^=(c=='-');c=getchar();}
while(isdigit(c)){x=x*10+c-48;c=getchar();}
if(sym)x=-x;
}
template<typename T,typename... Args>
void read(T& x,Args&... args){
read(x);read(args...);
}
int n,m,q;
set<int>mp[400001],mp2[400001];
int main(){
read(n,m,q);
int ans=n*m;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
mp[i].insert(j);
mp2[j].insert(i);
}
}
while(q--){
int x,y;
read(x,y);
auto it=mp[x].lower_bound(y);
if(it!=mp[x].end() and *it==y){
mp[x].erase(it);
mp2[y].erase(mp2[y].lower_bound(x));
ans--;
}
else{
if(it!=mp[x].begin()){
it--;
mp2[*it].erase(mp2[*it].lower_bound(x));
mp[x].erase(it);
ans--;
}
auto it2=mp[x].upper_bound(y);
if(it2!=mp[x].end()){
mp2[*it2].erase(mp2[*it2].lower_bound(x));
mp[x].erase(it2);
ans--;
}
auto it3=mp2[y].lower_bound(x);
if(it3!=mp2[y].begin()){
it3--;
mp[*it3].erase(mp[*it3].lower_bound(y));
mp2[y].erase(it3);
ans--;
}
auto it4=mp2[y].upper_bound(x);
if(it4!=mp2[y].end()){
mp[*it4].erase(mp[*it4].lower_bound(y));
mp2[y].erase(it4);
ans--;
}
}
}
cout<<ans<<endl;
}

需要注意 set 一定要用内置的 lower_bound() 函数!! ,否则复杂度直接多一个 \(n\log n\)

本题还有并查集做法,参见 \(\color{Red}\text{l}\color{black}\text{xyt}\ 大佬\) 的提交

E.Avoid K Partition \(\texttt{Diff }1453\)

给定一个数列,划分为若干非空子序列,要求没有任何子序列的和等于 \(K\),求方案数

\(N\le 2\times 10^{5}\)

考虑设计 \(f_{i}\) 表示考虑前 \(i\) 位的方案数,那么我们在从大到小枚举 \(i\) 的同时寻找断点,容易得到

\[f_{i}=\sum\{f_{j}[sum_{i}-sum_{j}\neq K]\}
\]

其中 \(sum\) 为前缀和数组.

因此有了 \(n^{2}\) 的解法,注意到 \(sum_{i}-sum_{j}=K\) 的数极少,因此可以提前处理出 \(\sum_{j}^{i-1}f_{j}\),然后直接减去不合法的即可,寻找不合法元素可以用 set 实现,复杂度 \(O(n\log n)\)

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define void inline void
template<typename T>
void read(T& x){
x=0;bool sym=0;char c=getchar();
while(!isdigit(c)){sym^=(c=='-');c=getchar();}
while(isdigit(c)){x=x*10+c-48;c=getchar();}
if(sym)x=-x;
}
template<typename T,typename... Args>
void read(T& x,Args&... args){
read(x);read(args...);
}
#define tests int cases;read(cases);while(cases--)
#define pb bush_back
const int p=998244353;
long long n,k,a[200001];
int main(){
read(n,k);
for(int i=1;i<=n;++i){
read(a[i]);
}
map<long long,long long>mp;
mp[0]=1;
long long ans=1;
long long sum=0;
for(int i=1;i<=n;++i){
sum+=a[i];
int res;
if(mp.count(sum-k)) res=ans-mp[sum-k];
else res=ans;
mp[sum]=(mp[sum]+res+p)%p;
ans=(ans+res+p)%p;
if(i==n) cout<<((res+p)%p)<<endl;
}
}

F.Cake Division

\(N\) 个元素的环形数列,分成 \(K\) 个连续段,最大化每个连续段和的最小值

并且求出在所有可能的方案中,哪两个元素在所有方案中都在同一个连续段内

\(N\le 2\times 10^{5}\)

[R18][中国語翻訳]HDKのABC370赛試(ABC370)的更多相关文章

  1. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  2. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  3. 2017年中国大学生程序设计竞赛-中南地区赛暨第八届湘潭市大学生计算机程序设计大赛题解&源码(A.高斯消元,D,模拟,E,前缀和,F,LCS,H,Prim算法,I,胡搞,J,树状数组)

    A------------------------------------------------------------------------------------ 题目链接:http://20 ...

  4. 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)

    若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...

  5. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 I. Reversion Count (java大数)

    Description: There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1 ...

  6. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 D Merchandise (斜率优化)

    Description: The elderly aunts always like to look for bargains and preferential merchandise. Now th ...

  7. TRANSLATE(转换大/小写并替换字符)

    可以将字母 转换大/小 写或使用替 换规则. 要转换大/小 写,请使用 TRANSLATE 语句,用法 如下: 语法 TRANSLATE <c> TO UPPER CASE. TRANSL ...

  8. ABAP CDS - SELECT, association

    ABAP CDS - SELECT, association Syntax ... ASSOCIATION [ [min..max] ] TO target [AS _assoc] ON cond_e ...

  9. PHP 7問世,2億網站效能翻倍有望

    經過10年的漫長等待,PHP 7終於正式問世了.這個影響全球8成網站的開發語言,一舉從5.0版,跳過了功敗垂成的6.0版,一舉進入了7.0時代. 20年前初夏,1995年6月8日,一位愛解決問題的C語 ...

  10. N4复习考试总结

    一つ(ひとつ) 半分(はんぶん) 煙草(たばこ)を吸う(すう) 玄関(げんかん) ナイフ(刀)     財布(さいふ) 浅い(あさい) 薄い(うすい) 牛乳(ぎゅうにゅう) 皿(さら) 七日(なのか) ...

随机推荐

  1. Docker Engine在Centos下的安装

    实践环境 Centos7.8 先决条件 CentOS 7.8. 必须开启 centos-extrasyum仓库源.默认是开启的,如果关闭了,需要重新开启,如下 编辑 /etc/yum.repos.d/ ...

  2. 【SQL】Lag/Rank/Over窗口函数揭秘,数据分析之旅

    七月的夏日,阳光如火,但小悦的心中却是一片清凉与激情.在数据分析项目组的新岗位上,她仿佛找到了自己新的舞台,这里让她得以将深厚的后端技术实力与数据分析的精髓深度融合.每天,她都沉浸在业务需求的分析与数 ...

  3. vue codemirro 文件对比 sql编辑器

    效果图: 安装及引用同上一篇文章,请移步:https://www.cnblogs.com/Lu-Lu/p/16265815.html HTML: <el-dialog class="d ...

  4. 从DDPM到DDIM(四) 预测噪声与后处理

    从DDPM到DDIM(四) 预测噪声与后处理 前情回顾 下图展示了DDPM的双向马尔可夫模型. 训练目标.最大化证据下界等价于最小化以下损失函数: \[\boldsymbol{\theta}^*=\u ...

  5. python获取引用对象的个数

    python获取引用对象的个数 使用sys.getrefcount()来获取当前对象被引用了多少次,返回的结果比实际大1 import sys class A: pass a = A() #创建实例对 ...

  6. 【Mybatis】04 官方文档指北阅读 vol2 配置 其一

    https://mybatis.org/mybatis-3/zh/configuration.html 配置 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置和属性信息. 配置文 ...

  7. 训练人形机器人时如何收集人类行为数据 —— 通过人来训练机器人(真人实际演示动作)or 仿真环境自动生成 —— 哪种方式更优、更可行呢

    特斯拉的老马,搞的optimus人形机器人就是通过人来训练机器人(真人实际演示动作),但是未来使用仿真环境自动生成数据是否可行呢,NVIDIA的老黄在2024 GTC上是大力推出自家的GROOT平台, ...

  8. ubuntu 配置NTP时间服务器&&定时同步本地时间

    Ubuntu系统: NTP时间服务器的安装: 服务器安装命令: sudo apt-get install ntp NTP服务配置,设置为本地时间服务器,屏蔽默认server,服务器层级设为10: vi ...

  9. 分布式深度学习计算框架依赖环境——NCCL的安装

    分布式深度学习计算框架(MindSpore, PyTorch)依赖环境--NCCL, NCCL提供多显卡之间直接进行数据交互的功能(可以跨主机进行). 注意: 本文环境为  Ubuntu18.04 以 ...

  10. C# 命名空间和程序集 小记

    前言 本文只是为了复习,巩固,和方便查阅,一些知识点的详细知识会通过相关链接和文献标记出来. 命名空间 1.1 概念 可以把命名空间看做字符串,他加在类名或类型名前面并且通过点进行分割 既然看做是字符 ...