题意:

问一个数组中是否存在至少长为3的回文子数组(按下标排列,可不连续)。

思路:

找三个相同数或两个不连续的相同数。

#include <bits/stdc++.h>
using namespace std; const int M=5500; void solve(){
int last[M]={0},cnt[M]={0}; int n;cin>>n;
int a[n+1];for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){
if((++cnt[a[i]]==3)||(last[a[i]]&&last[a[i]]!=i-1)){
cout<<"YES\n";
return;
}
last[a[i]]=i;
} cout<<"NO\n";
} int main(){
int t;cin>>t;
while(t--)
solve();
return 0;
}

更新 :

二者实为一种情况。

#include <bits/stdc++.h>
using namespace std; const int M=5500; void solve(){
int first[M]={0}; int n;cin>>n;
int a[n+1];for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){
if(first[a[i]]==0){
first[a[i]]=i;
}
else if(first[a[i]]<i-1){
cout<<"YES\n";
return;
}
} cout<<"NO\n";
} int main(){
int t;cin>>t;
while(t--)
solve();
return 0;
}

Codeforces Round #627 (Div. 3) B - Yet Another Palindrome Problem(逻辑)的更多相关文章

  1. Codeforces Round #627 (Div. 3) A - Yet Another Tetris Problem(逻辑)

    题意 : 有n个高度,可以使任一高度加二任意次,问最终n个高度可否相同. 思路: 因为添加的2x1的方块不可旋转,只需考虑所有高度是否为同一奇偶性即可. #include <bits/stdc+ ...

  2. Codeforces Round #627 (Div. 3)

    1324A - Yet Another Tetris Problem(思维) 题意 给一个数组,每一个数组中的元素大小表示在竖直方向的方块数量,元素相邻怎竖直方向的方块也相邻,类似于俄罗斯方块当底层被 ...

  3. [每日一题2020.06.07]codeforces Round #627 (Div. 3)

    problem A /* * Author: RoccoShi * Time: 2020-06-07 19:37:51 */ #include <bits/stdc++.h> using ...

  4. Codeforces Round #627 (Div. 3) F - Maximum White Subtree(深度优先搜索)

    题意: n 个点 n - 1 条边的树,问每个点所在所有子树中白黑点数目的最大差. 思路: 白点先由下至上汇集,后由上至下分并. #include <bits/stdc++.h> usin ...

  5. Codeforces Round #627 (Div. 3) E - Sleeping Schedule(递推)

    题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点 ...

  6. Codeforces Round #627 (Div. 3) D - Pair of Topics(双指针)

    题意: 有长为n的a,b两序列,问满足ai+aj>bi+bj(i<j)的i,j对数. 思路: 移项得:(ai-bi)+(aj-bj)>0,i<j即i!=j,用c序列保存所有ai ...

  7. Codeforces Round #627 (Div. 3) C - Frog Jumps(逻辑)

    题意: 有一个每个单元标明移动方向的长为n的序列,每次移动不能超过距离k,问能够从0移动到n+1的k的最小值. 思路: k=最长连续L序列长度+1. #include <bits/stdc++. ...

  8. Codeforces Round #410 (Div. 2)C. Mike and gcd problem

    题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...

  9. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

随机推荐

  1. Python+MySQL随机试卷及答案生成程序

    一.背景 本文章主要是分享如何使用Python从MySQL数据库中面抽取试题,生成的试卷每一份都不一样. 二.准备工作 1.安装Python3 下载地址:https://www.python.org/ ...

  2. 【ASM】介绍Oracle自带的一些ASM维护工具 (kfod/kfed/amdu)

    转自:http://blog.csdn.net/wenzhongyan/article/details/47043253 非常感谢作者的文章,很有价值!至此转载,非常感谢 1.前言 ASM(Autom ...

  3. LeetCode1022. 从根到叶的二进制数之和

    题目 class Solution { public: int ans = 0; int sumRootToLeaf(TreeNode* root) { dfs(root,0); return ans ...

  4. Lnux:实验 Linux C 编程

    实验题目: 实验 3 Linux C 编程 实验目的和要求:   熟悉 Linux 操作系统环境 在 Linux 下编写.执行简单的 C 程序 用 C 语言写自己的 Linux 命令 实验过程: 认真 ...

  5. 24V降压3.3V芯片,低压降线性稳压器

    PW6206系列是一款高精度,高输入电压,低静态电流,高速,低压降线性稳压器具有高纹波抑制.在VOUT=5V&VIN=7V时,输入电压高达40V,负载电流高达300mA,采用BCD工艺制造.P ...

  6. MYSQL基础知识的复习1

    数据库(是存放数据的仓库) 1.根据存储量以及安全性上来划分: 大型数据库:DB2 Oracle(毕业) Hbase 银行 公安局(不加班 没网) 移动 中型数据库:mysql sqlserver(. ...

  7. innodb引擎的4大特性

    一:插入缓冲 二:二次写 三:自适应哈希 四:预读 1.插入缓冲(insert buffer)插入缓冲(Insert Buffer/Change Buffer):提升插入性能,change buffe ...

  8. Linux防火墙和iptables

    1. CentOS 查看防火墙状态: systemctl status firewalld firewall-cmd --state 启停防火墙: # 开启 systemctl start firew ...

  9. Golang 单元测试:有哪些误区和实践?

    https://mp.weixin.qq.com/s/k8WNWpCIVl4xTmP3TQ_gxQ

  10. protoc-gen-validate (PGV)

    https://github.com/envoyproxy/protoc-gen-validate This project is currently in alpha. The API should ...