C. Turtle and an Incomplete Sequence

2024-06-01 08:20
文章标签 sequence turtle incomplete

本文主要是介绍C. Turtle and an Incomplete Sequence,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

思路:首先如果都是-1的话,我们可以输出1 2循环,否则。

首先处理首尾的连续-1串,这个也很好处理,最后我们处理两个非-1之间的-1串。

对于左边的数a[l]和右边的数a[r]:

如果a[l] > a[r],那么就处理a[l + 1],让左边的数变小,否则处理a[r - 1]。

代码:

void solve() {int n;std::cin >> n;std::vector<int> a(n);for (int i = 0; i < n; i++) {std::cin >> a[i];}if (std::count(a.begin(), a.end(), -1) == n) {for (int i = 0; i < n; i++) {a[i] = i % 2 + 1;}} else {for (int i = 0, j = -1; i <= n; i++) {if (i == n || a[i] != -1) {if (j == -1) {for (int k = i - 1; k >= 0; k--) {a[k] = a[k + 1] == 1 ? 2 : a[k + 1] / 2;}} else if (i == n) {for (int k = j + 1; k < n; k++) {a[k] = a[k - 1] == 1 ? 2 : a[k - 1] / 2;}} else {int l = j, r = i;while (l + 1 < r) {if (a[l] > a[r]) {a[l + 1] = a[l] == 1 ? 2 : a[l] / 2;l++;} else {a[r - 1] = a[r] == 1 ? 2 : a[r] / 2;r--;}}if (a[l] != a[r] / 2 && a[r] != a[l] / 2) {std::cout << -1 << "\n";return;}}j = i;}}}for (int i = 0; i < n; i++) {std::cout << a[i] << " \n"[i == n - 1];}
}

这篇关于C. Turtle and an Incomplete Sequence的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1020480

相关文章

「Debug R」如何处理Error in readLines(f) :(converted from warning) incomplete final line found on xxx...

用devtools::install_github从GitHub上安装一个R包的时候出现了报错, 报错截图如下所示: 报错 从报错内容基本上可以确定是换行符惹的祸,我将该文件传送到Linux下,用cat -A检查,发现最后一行后面没有换行符。 ^M是Windows的换行符 解决方案: 手动增加最后一行。 手动加换行 到此当前的

tessy 单元测试 TDE 界面 数据无法填充:the test object interface is incomplete

目录 1,失败现象 2,失败原因 3,解决办法 1,失败现象         函数名字前的图标高度缩小为正常的一半,TDE界面的数据无法填充。错误提示为题目中的英文。 2,失败原因         TIE界面,此函数的参数的 passing 方向有 unknown,未正确识别。 3,解决办法         将 interface 栏的所有参数的 passing 和

论文浅读之Mamba: Linear-Time Sequence Modeling with Selective State Spaces

介绍 这篇论文提出了一种新型的"选择性状态空间模型"(Selective State Space Model, S6)来解决之前结构化状态空间模型(SSM)在离散且信息密集的数据(如文本)上效果较差的问题。 Mamba 在语言处理、基因组学和音频分析等领域的应用中表现出色。其创新的模型采用了线性时间序列建模架构,结合了选择性状态空间,能够在语言、音频和基因组学等不同模式中提供卓越的性能。这种突破

mysql实现sequence自增长

1、创建表tb_sequence,用来存放sequence值:   create table tb_sequence(name varchar(50) not null,current_value int not null,_increment int not null default 1, primary key(name));     2.现在插入一条记录  insert into t

PAT甲级 1085 Perfect Sequence 二分和双指针(Two Pointers)

二分写法 #include <bits/stdc++.h>using namespace std;int find_upper_bound(const vector<long long>& nums, long long x){int beg = 0, end = nums.size(), mid = beg + (end - beg) / 2;while (beg < end) {mid

2.5 how do I iterate over a sequence in reverse order

So: 序列(包含列表、元祖以及字符串)中好像就只有列表有a.reverse() 但都有reversed(a) 一、http://www.mianwww.com/html/2009/08/3615.html 如果是一个list, 最快的解决方案是: list.reverse() try: for x in list: “do something with x” finally: li

安装Docker Desktop报错WSL 2 installation is incomplete(实操教程)

点击运行提示WSL2安装不完整问题描述:WSL 2 installation is incomplete. The WSL 2 Linux kernel is now installed using a separate MSl updatepackage. Please click the link and follow the instructions to install thekernel

POJ2478 Farey Sequence【快速求欧拉函数】

题目链接: http://poj.org/problem?id=2478 题目大意: 给你一个数n,对于0 < a < b <= n,求真分数a/b的个数 解题思路: 因为a/b为真分数,所以a和b互质。 求真分数a/b的个数。其实就是求0 < i <= n中,小于i的正整数中, 有多少个与i互质的数。累加起来就是真分数a/b的个数。 其实就是

PAT甲级真题及训练集(6)--1051. Pop Sequence (25)

1051. Pop Sequence (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a stack which can keep M numbers at most. Push N numbers in the order o

poj3017 Cut the Sequence 单调队列优化dp 好题!

Language: Default Cut the Sequence Time Limit: 2000MS Memory Limit: 131072KTotal Submissions: 8766 Accepted: 2578 Description