此题就是:给你一个数组,让你找出两个不同的元素,并让它们的下标差距最大。

思路:从2到n,如果与1不同,记录距离,与原数比较,取大。 从1到n-1,如果与n不同,记录距离,与原数比较,取大。

AC代码(你们最想要的)

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[300010],i,ans=0;
cin>>n;
for(i=1;i<=n;i++)cin>>a[i];//输入
for(i=n;i>1;i--){//从21到n循环求解
if(a[1]!=a[i]){
ans=max(ans,i-1);//取大
}
}
for(i=1;i<n;i++){//从n-1到n循环求解
if(a[n]!=a[i]){
ans=max(ans,n-i);//取大
}
}
cout<<ans;
return 0;//华丽丽的结束
}

管理员求过

题解 CF1119A 【Ilya and a Colorful Walk】的更多相关文章

  1. CF1119A Ilya and a Colorful Walk

    题目地址:CF1119A Ilya and a Colorful Walk \(O(n^2)\) 肯定过不掉 记 \(p_i\) 为从下标 \(1\) 开始连续出现 \(i\) 的个数 那么对于每一个 ...

  2. CF1119A Ilya and a Colorful Walk 题解

    Content 有一个长度为 \(n\) 的数组 \(a_1,a_2,a_3,...,a_n\),试求出两个不相等的数之间的距离的最大值. 数据范围:\(3\leqslant n\leqslant 3 ...

  3. 题解报告:hdu 1142 A Walk Through the Forest

    题目链接:acm.hdu.edu.cn/showproblem.php?pid=1142 Problem Description Jimmy experiences a lot of stress a ...

  4. [题解] [CF518D] Ilya and Escalator

    题面 题解 期望dp入门题 设\(f[i][j]\)为到\(i\)时间有\(j\)个人上了电梯的概率, 我们可以得到转移方程 \[ f[i][j]=\begin{cases}f[i-1][j]\cdo ...

  5. CF1119 Global Round 2

    CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ...

  6. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  7. Codeforces Global Round 2部分题解

    传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...

  8. Codeforces Global Round 2 Solution

    这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...

  9. Global Round 2

    A - Ilya and a Colorful Walk CodeForces - 1119A Ilya lives in a beautiful city of Chordalsk. There a ...

随机推荐

  1. 【leetcode】1213.Intersection of Three Sorted Arrays

    题目如下: Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, return a s ...

  2. VS2017 + EF + MySQL 环境配置

    我使用过程中遇到的坑(血泪啊) 安装环境VS2017MVC+WIN10+EF6+MySQL8.0.12 1.安装MySQL connector一定要6.10.8,8.0以上全是坑,会闪退!!! 2.安 ...

  3. 20180804 excel规划求解。。。

    把一个已经变量更出数据去求解

  4. 【BZOJ2022】Pku1837 Balance

    Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...

  5. java语言课堂动手动脑

    1 运行 TestInherits.java 示例,观察输出,注意总结父类与子类之间构造方法的调用关系修改Parent构造方法的代码,显式调用GrandParent的另一个构造函数,注意这句调用代码是 ...

  6. QT 信号槽 异步事件驱动 单线程 多并发

    利用好Qt 模块的异步信号槽,单线程同样可是实现很强悍的的并发能力.应付正常的功能是足够的. 需要注意的是:该模式本质上为 单线程 事件驱动异步模式,所以需要做的事优化你的业务代码构架以应付性能与并发 ...

  7. prometheus 监控项

    此处记录prometheus监控项,exporter为 node_exporter vim rules.yml groups: - name: node rules: - alert: server_ ...

  8. 聊聊 Vue 的双向数据绑定,Model 如何改变 View,View 又是如何改变 Model 的

    todo defineProperty() 参考: https://www.cnblogs.com/wangjiachen666/p/9883916.html

  9. windows7 中 wacom数位板如何关闭点击水波 和长按右键这两个特效

    就是点住笔尖不动,就会弹出右键,这个功能是微软操作系统具有的一项功能,,如果您感觉不便,可以按以下方法将其去掉: 1.打开"控制面板--笔和触摸--笔选项--按下并保持--设置": ...

  10. iOS证书详解

    一.成员介绍1.    Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1)    Developer Certification(开发证书)安装在电脑上 ...