题解 CF1119A 【Ilya and a Colorful Walk】
此题就是:给你一个数组,让你找出两个不同的元素,并让它们的下标差距最大。
思路:从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】的更多相关文章
- CF1119A Ilya and a Colorful Walk
		题目地址:CF1119A Ilya and a Colorful Walk \(O(n^2)\) 肯定过不掉 记 \(p_i\) 为从下标 \(1\) 开始连续出现 \(i\) 的个数 那么对于每一个 ... 
- CF1119A Ilya and a Colorful Walk 题解
		Content 有一个长度为 \(n\) 的数组 \(a_1,a_2,a_3,...,a_n\),试求出两个不相等的数之间的距离的最大值. 数据范围:\(3\leqslant n\leqslant 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 ... 
- [题解] [CF518D] Ilya and Escalator
		题面 题解 期望dp入门题 设\(f[i][j]\)为到\(i\)时间有\(j\)个人上了电梯的概率, 我们可以得到转移方程 \[ f[i][j]=\begin{cases}f[i-1][j]\cdo ... 
- CF1119 Global Round 2
		CF1119A Ilya and a Colorful Walk 这题二分是假的.. \(1,2,1,2,1\) 有间隔为 \(3\) 的,但没有间隔为 \(2\) 的.开始被 \(hack\) 了一 ... 
- Codeforces Global Round 2 题解
		Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ... 
- Codeforces Global Round 2部分题解
		传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ... 
- 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-> ... 
- Global Round 2
		A - Ilya and a Colorful Walk CodeForces - 1119A Ilya lives in a beautiful city of Chordalsk. There a ... 
随机推荐
- UVA 11090 : Going in Cycle!! 【spfa】
			题目链接 题意及题解参见lrj训练指南 #include<bits/stdc++.h> using namespace std; const double INF=1e18; ; ; in ... 
- CF1263F
			题目描述 给出一个类似这样 的图,求删掉最多的黑边使得每个特殊点和至少一个节点1连通 保证上下两棵树都存在一种dfs序使得访问特殊点的顺序为1~n 题解 设f[i][j]表示上面的树最后一个特殊点为i ... 
- cpp 实现简易String类
			需求 实现一个String类 自己写的String headers/String.h #ifndef __MYSTRING__ #define __MYSTRING__ #include <st ... 
- PISCES: A Programmable, Protocol-Independent Software Switch
			Name of article:PISCES: A Programmable, Protocol-Independent Software Switch Origin of the article:S ... 
- PO,BO,VO和POJO的区别
			PO:persistent object 持久对象 1 .有时也被称为Data对象,对应数据库中的entity,可以简单认为一个PO对应数据库中的一条记录. 2 .在hibernate持久化框架中与i ... 
- 聊聊 Vue 的双向数据绑定,Model 如何改变 View,View 又是如何改变 Model 的
			todo defineProperty() 参考: https://www.cnblogs.com/wangjiachen666/p/9883916.html 
- jieba(结巴)常用方法
			python jieba库的基本使用 第一步:先安装jieba库 输入命令:pip install jieba jieba库常用函数: jieba库分词的三种模式: 1.精准模式:把文本精准地分开 ... 
- STOMP协议详解
			STOMP协议详解 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 一.STOMP协议介绍 STOMP即Simple (or Streaming) T ... 
- sensu
			https://blog.csdn.net/enweitech/article/details/53763324 
- JRE、JDK、JVM 及 JIT 之间有什么不同
			java虚拟机(JVM) 使用java编程语言的主要优势就是平台的独立性.你曾经想知道过java怎么实现平台的独立性吗?对,就是虚拟机,它抽象化了硬件设备,开发者和他们的程序的得以操作系统.虚 ... 
