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)的更多相关文章

  1. AtCoder Beginner Contest 238 A - F 题解

    AtCoder Beginner Contest 238 \(A - F\) 题解 A - Exponential or Quadratic 题意 判断 \(2^n > n^2\)是否成立? S ...

  2. AtCoder Beginner Contest 131 Task F. Must Be Rectangular

    Score: 600 points Approach 固定横坐标 $x$,考虑横坐标为 $x$ 的竖直线上最多可以有几个点. Observations 若最初两条竖直线 $x_1$.$x_2$ 上都有 ...

  3. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  6. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  7. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  8. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

  9. 题解 AtCoder Beginner Contest 168

    小兔的话 欢迎大家在评论区留言哦~ AtCoder Beginner Contest 168 A - ∴ (Therefore) B - ... (Triple Dots) C - : (Colon) ...

随机推荐

  1. React + Typescript领域初学者的常见问题和技巧

    React + Typescript领域初学者的常见问题和技巧 创建一个联合类型的常量 Key const NAME = { HOGE: "hoge", FUGA: "f ...

  2. SAP Picture Control(图片加载)

    Screen display 效果 源代码 program sap_picture_demo. set screen 200. TYPE-POOLS cndp. ******************* ...

  3. DDos、CC攻击与防御

    DDoS介绍 DDoS是英文Distributed Denial of Service的缩写,意即"分布式拒绝服务",那么什么又是拒绝服务(Denial of Service)呢? ...

  4. UiPath文本操作Get Full Text的介绍和使用

    一.Get Full Text操作的介绍 使用Get Full Text(获取全文本 )屏幕抓取方法从指示的UI元素中提取字符串及其信息 二.Get Full Text在UiPath中的使用 1. 打 ...

  5. 鼠标右键打开powershell

    不需要更改配置文件什么的. 在桌面空白处按住Shift键同时鼠标右击,看看是不是就有了呢.

  6. 利用MySQL中的乐观锁和悲观锁实现分布式锁

    背景 对于一些并发量不是很高的场景,使用MySQL的乐观锁实现会比较精简且巧妙. 下面就一个小例子,针对不加锁.乐观锁以及悲观锁这三种方式来实现. 主要是一个用户表,它有一个年龄的字段,然后并发地对其 ...

  7. 笔记本USB接口案例分析和是实现

    笔记本电脑 笔记本电脑(laptop)通常具备使用USB设备的功能.在生产时,笔记本都预留了可以插入USB设备的USB接口,但具体是什么USB设备,笔记本厂商并不关心,只要符合USB规格的设备都可以 ...

  8. 攻防世界MISC进阶区---41-45

    41.Get-the-key.txt 得到无类型文件,扔进kali中,strings一下,得到了一堆像flag的内容 扔进010 Editor中,搜索关键字,发现一堆文件,改后缀为zip 打开,直接得 ...

  9. 集合—collection、iterator遍历集合

    一.collection接口 1.collection常用方法 点击查看代码 @Test public void test(){ //contains() Collection coll = new ...

  10. Solution -「Luogu 5170」类欧几里得算法

    推柿子大赛了属于是. 题目要求三个柿子,不妨分别记为: \[\begin {align} f (a, b, c, n) &= \sum \limits _{i = 0} ^{n} \lfloo ...