C. Dominant Piranha(思维)

https://codeforces.com/contest/1433/problem/C


思路:找序列中最大的,如果满足有一个最大的数旁边存在比它小的数,那么必然能YES,输出这个数位置即可。如果不能满足就是NO。

 

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+100;
typedef long long LL;
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	LL n;cin>>n;
  	for(LL i=0;i<=n+10;i++) a[i]=0; 
  	for(LL i=1;i<=n;i++) cin>>a[i];
  	LL mx=-1e18;
  	for(LL i=1;i<=n;i++){
  		if(mx<a[i]) mx=a[i];	
	}
	//LL sum=0;
	LL pos1=0;
	for(LL i=1;i<=n;i++){
		if(mx==a[i]) {
			//if(((i-1)!=0&&a[i]>a[i-1])&&(a[i]>a[i+1]&&(i+1)!=n))
		//	{
			//	pos1=i;break;
			//}	
			if(i==1&&a[1]>a[2]){
				pos1=1;break;
			}
			else if(i==n&&a[n]>a[n-1]){
				pos1=n;break;
			}
			else if( ((i!=1)&&a[i]>a[i-1])||(i!=n&&a[i]>a[i+1])){
				pos1=i;break;
			}
		}
	}
	if(pos1==0){
		cout<<"-1"<<endl;
	}
	else cout<<pos1<<endl;
  }
return 0;
}
 

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值