[R18][中国語翻訳]HDKのABC370赛試(ABC370)
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\) 的同时寻找断点,容易得到
\]
其中 \(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)的更多相关文章
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- 2017年中国大学生程序设计竞赛-中南地区赛暨第八届湘潭市大学生计算机程序设计大赛题解&源码(A.高斯消元,D,模拟,E,前缀和,F,LCS,H,Prim算法,I,胡搞,J,树状数组)
A------------------------------------------------------------------------------------ 题目链接:http://20 ...
- 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)
若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...
- 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 ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 D Merchandise (斜率优化)
Description: The elderly aunts always like to look for bargains and preferential merchandise. Now th ...
- TRANSLATE(转换大/小写并替换字符)
可以将字母 转换大/小 写或使用替 换规则. 要转换大/小 写,请使用 TRANSLATE 语句,用法 如下: 语法 TRANSLATE <c> TO UPPER CASE. TRANSL ...
- ABAP CDS - SELECT, association
ABAP CDS - SELECT, association Syntax ... ASSOCIATION [ [min..max] ] TO target [AS _assoc] ON cond_e ...
- PHP 7問世,2億網站效能翻倍有望
經過10年的漫長等待,PHP 7終於正式問世了.這個影響全球8成網站的開發語言,一舉從5.0版,跳過了功敗垂成的6.0版,一舉進入了7.0時代. 20年前初夏,1995年6月8日,一位愛解決問題的C語 ...
- N4复习考试总结
一つ(ひとつ) 半分(はんぶん) 煙草(たばこ)を吸う(すう) 玄関(げんかん) ナイフ(刀) 財布(さいふ) 浅い(あさい) 薄い(うすい) 牛乳(ぎゅうにゅう) 皿(さら) 七日(なのか) ...
随机推荐
- 学习笔记--Java方法重载
Java方法重载 感受 以下代码不使用"方法重载",不使用overload,分析程序存在的缺点 public class OverloadTest01 { // 入口 public ...
- CF1956B Nene and the Card Game 题解
Nene and the Card Game 题意 有 \(2n\) 张牌,\(1,2,3,\dots,n\) 皆有两张. 有两个人在玩游戏,每个人有 \(n\) 张卡片,当一人出了一张编号为 \(k ...
- nats 简介和使用
nats 简介和使用 nats 有 3 个产品 core-nats: 不做持久化的及时信息传输系统 nats-streaming: 基于 nats 的持久化消息队列(已弃用) nats-jetstre ...
- windows10 idea springboot项目部署
windows10 idea springboot项目部署 一,springboot项目 本次项目在原项目的基础之上进行了二次开发:添加了index.html页面 根据配置文件配置数据库 先创建数据库 ...
- vue pinia sessionstorage 数据存储不上的原因
vue pinia sessionstorage 的坑 默认的配置是开始 localStorage 如果用 sessionstorage 则发现数据存储不上 ,是因为缺少了序列化和反序列化 impor ...
- 【Spring-Cloud】Nacos2.0.3 单系统集群部署问题汇总
1.强制要求JDK8版本 且 64位 C:\Users\Administrator\Desktop\Nacos-Server\Nacos-2.0.3-8848\bin>java -version ...
- 【Java】逗号拼接的取巧处理
需求如图: 这是表的关键处理数据,页面上的输入框要做分开展示,也就是要写业务逻辑来处理 逗号拼接的取巧处理,使用了List集合toString方法来实现,然后移除括号 final String emp ...
- 人工智能(AI)未来之方向:努力培养人才、科研创新!
地址: https://baijiahao.baidu.com/s?id=1801824912676717630&wfr=spider&for=pc 人工智能(AI)未来之方向 1. ...
- 并行化强化学习 —— 最终版本 —— 并行reinforce算法的尝试
本文代码地址: https://gitee.com/devilmaycry812839668/final_-version_-parallelism_-reinforce_-cart-pole 结合了 ...
- baselines算法库common/vec_env/vec_env.py模块分析
common/vec_env/vec_env.py模块内容: import contextlib import os from abc import ABC, abstractmethod from ...