AtCoder Beginner Contest 255(E-F)
Aising Programming Contest 2022(AtCoder Beginner Contest 255) - AtCoder
E - Lucky Numbers
题意: 给两个数组a,b,构成一个S数组,保证S[i]+S[i]+1==a[i],问S数组中出现的元素中,与b数组相同的最多有几个。
题解: 首先要知道,你确定了这个数组中的某一个值,那么其他的值也就确定了,所以,我们可以让最少有一个相同的,所以每个位置遍历b数组的几种数字。
首先我们构成一个第一位为0的S数组,然后可以发现,如果第一位+1,那么奇数位置都加一,偶数位置都减一,所以每次判断选择的数字和以0为开始的S数组的中你要替换的哪一项的差值,然后判断奇偶,记录一下即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=2e5+5;
const ll inf=1e18;
const ll mod=998244353;
ll a[N],b[N],sum[N];
map<ll,ll> mp;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n,m;cin>>n>>m;
for(ll i=1;i<=n-1;i++) cin>>a[i];
for(ll i=1;i<=m;i++) cin>>b[i];
for(ll i=2;i<=n;i++) sum[i]=a[i-1]-sum[i-1];
for(ll i=1;i<=n;i++)
for(ll j=1;j<=m;j++){
ll pt=sum[i]-b[j];//记录差值
if(i&1) pt*=-1;//判断奇偶
mp[pt]++;//存储
}
ll ans=-inf;
for(auto it:mp) ans=max(ans,it.second);
cout<<ans;
}
F - Pre-order and In-order
题意: 给出先序中序,判断能否构成一个根节点为1的树,能的话每个点的左右节点是多少
题解: 根据先序遍历找出对应元素在中序遍历的位置,对应的肯定是一个中点,然后分为左右两块遍历即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=2e5+5;
const ll inf=1e18;
const ll mod=998244353;
ll f[N],mid[N];
ll cnt,idx[N];
ll ansl[N],ansr[N];
ll solve(ll l,ll r){
if(l>r) return 0;
cnt++;
ll p=f[cnt];ll pt=idx[p];
if(pt<l||pt>r){//判断是否越界
cout<<"-1";exit(0);
}
ansl[p]=solve(l,pt-1);
ansr[p]=solve(pt+1,r);
return p;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n;cin>>n;
for(ll i=1;i<=n;i++) cin>>f[i];
for(ll i=1;i<=n;i++) { cin>>mid[i];idx[mid[i]]=i;}
if(f[1]!=1){
cout<<"-1";
return 0;
}
solve(1,n);
for(ll i=1;i<=n;i++){
cout<<ansl[i]<<" "<<ansr[i]<<endl;
}
}
AtCoder Beginner Contest 255(E-F)的更多相关文章
- AtCoder Beginner Contest 238 A - F 题解
AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...
- AtCoder Beginner Contest 131 Task F. Must Be Rectangular
Score: 600 points Approach 固定横坐标 $x$,考虑横坐标为 $x$ 的竖直线上最多可以有几个点. Observations 若最初两条竖直线 $x_1$.$x_2$ 上都有 ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 161
比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...
- 题解 AtCoder Beginner Contest 168
小兔的话 欢迎大家在评论区留言哦~ AtCoder Beginner Contest 168 A - ∴ (Therefore) B - ... (Triple Dots) C - : (Colon) ...
随机推荐
- jvm造轮子
博客内容来源于 刘欣老师的课程,刘欣老师的公众号 码农翻身 博客内容来源于 Java虚拟机规范(JavaSE7) 博客内容的源码 https://gitee.com/zumengjie/litejvm ...
- pyenv安装及使用教程
pyenv安装及使用教程 pyenv 安装 git clone https://github.com/pyenv/pyenv.git ~/.pyenv # 编辑 bashrc vim ~/.bashr ...
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
论文信息 论文标题:Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data论文作者:Qi Zhu, ...
- bat-Office激活命令
激活命令 cd C:\Program Files\Microsoft Office\Office16 //然后目录对的话,该目录下面应该有个 OSPP.VBS cscript ospp.vbs /ds ...
- MySql字段增删改语句
新增表字段:alter table 表名 需要添加的字段信息; ALTER TABLE nation add seq VARCHAR(20) COMMENT '顺序' 字段名的修改:alter tab ...
- 使用EasyExcel导出图片及异常处理
1.使用String类型导出 定义自己的Converter,不使用默认的StringImageConverter 如果图片路径为空或者图片路径是错误的,返回相应的内容 import java.io ...
- NC20439 [SHOI2017]期末考试
NC20439 [SHOI2017]期末考试 题目 题目描述 有 \(n\) 位同学,每位同学都参加了全部的 \(m\) 门课程的期末考试,都在焦急的等待成绩的公布.第 \(i\) 位同学希望在第 \ ...
- tauri+vue开发小巧的跨OS桌面应用-股票体检
最近打算写一个用于股票体检的软件,比如股权质押比过高的股票不合格,ROE小于10的股票不合格,PE大于80的股票不合格等等等等,就像给人做体检一样给股票做个体检.也实现了一些按照技术指标.基本面自动选 ...
- browserify的standalone的含义
白话:就像Jquery的$, 把你打包后的函数挂在window下你指定的名字下 废话:白话看不懂,就看下面的废话,你不得不花更多时间理解--standalone AAA的含义$ browserify ...
- API 开发者需要避免的10个错误【翻译】
随着低代码和无代码工具的出现,构建API比以往任何时候都更简单.更快.不过因为开发简单了,开发者很容易忽略一些潜在的问题,导致整个业务的下游影响. 在设计阶段多花点时间,可以确保API真正有用.安全. ...