当前位置:网站首页>12 至少是其他数字两倍的最大数
12 至少是其他数字两倍的最大数
2022-07-17 00:07:00 【DHU杨骅麟(紫外线过敏)】
12 至少是其他数字两倍的最大数
作者: Turbo时间限制: 1S章节: 课程设计
问题描述 :
给你一个整数数组 nums ,其中总是存在 唯一的 一个最大整数 。
请你找出数组中的最大元素并检查它是否 至少是数组中每个其他数字的两倍 。如果是,则返回 最大元素的下标 ,否则返回 -1 。
示例 1:
输入:
4
3 6 1 0
输出:1
解释:6 是最大的整数,对于数组中的其他整数,6 至少是数组中其他元素的两倍。6 的下标是 1 ,所以返回 1 。
示例 2:
输入:
4
1 2 3 4
输出:-1
解释:4 没有超过 3 的两倍大,所以返回 -1 。
示例 3:
输入:
1
1
输出:0
解释:因为不存在其他数字,所以认为现有数字 1 至少是其他数字的两倍。
输入说明 :
输入两行:
第一行输入一个整数n表示数组nums的长度。
第二行输入n个整数表示数组的元素。
提示:
1 <= n <= 100
0 <= nums[i] <= 100
nums 中的最大元素是唯一的
输出说明 :
输出一个整数表示结果。
输入范例 :
5
5 4 3 2 1
输出范例 :
-1
#include<iostream>
#include<algorithm>
using namespace std;
struct student
{
int data = 0;
int sequence = 0;
};
bool cmp(student x, student y)
{
return x.data > y.data;
}
int main()
{
student arr[10001] ;
int n = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i].data;
arr[i].sequence = i;
}
sort(arr, arr + n, cmp);
if (arr[0].data > 2 * arr[1].data)
{
cout << arr[0].sequence;
}
else
{
cout << -1;
}
return 0;
}边栏推荐
- [GFCTF 2021]Baby_ Cve-2021-41773 on the web
- Uni scroll view pull-down refresh
- Use leaflet to copy the original shentiwa Mega map to make a diary
- qs模块是?
- Promise的基本使用
- The difference between let and VaR
- Quine injection of SQL injection
- PCRE bypasses regular
- Yii2反序列化漏洞复现
- Summary of XML external entity injection (xxE target recurrence)
猜你喜欢

JSX 语法

tp-watermark. JS web page add watermark plug-in

Differences between let and const, let, const and VaR

软件漏洞分析入门(三)

js获取一个文件名的后缀格式

How does the website count the number of visitors? How to install and use 51la?

uni-app微信小程序——商城(8)——订单详情

Uni app wechat applet - Mall (8) - order details

深拷贝与浅拷贝

Deployment of cobalstrike (with resources)
随机推荐
let和const、let、const和var的区别
Text indent in uniapp doesn't work, and the indentation in the first line of uniapp doesn't work. How to solve it?
Colorful text advertising code, text advertising code beautification version, add text advertising tutorials to the website
V-model principle and modifier
时间戳转化时间
Uni app wechat official account (1) - Web page authorization login
Libtomcrypt密码库的使用
今天的码农女孩总结了关于npm包管理和url模块的笔记
记一次用canvas做出腾讯云首页banner流光效果的经历
Nodejs cross domain CORS
05_ Review object defineProperty
Collection and summary of penetration test information
object-fit:cover; It doesn't work in the applet. How to deal with the deformation of the applet image
解决小程序自定义底部菜单切换闪动
JS string to object JS object to string JS string to object
红日安全靶场3
05_回顾Object.defineProperty
js替换字符串某个字符,js修改字符串中指定字符
使用redis - zset做排行榜
v-model原理及修饰符