博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
8月10日训练报告
阅读量:3951 次
发布时间:2019-05-24

本文共 2496 字,大约阅读时间需要 8 分钟。

这两天比赛思维题比较多,算法设计的比较少,今天看了矩阵快速幂的内容,刷了几道以前比赛没做出来的思维题,今晚的比赛的A题感觉是道水题,但在当时没做出来。

赛后网上找了大佬的思路,很是清晰。

B. Unsorting Array

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.

Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions:

  1. a1 ≤ a2 ≤ ... ≤ an;
  2. a1 ≥ a2 ≥ ... ≥ an.

Help Petya find the two required positions to swap or else say that they do not exist.

Input

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.

Output

If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.

Examples

input

Copy

11

output

Copy

-1

input

Copy

21 2

output

Copy

-1

input

Copy

41 2 3 4

output

Copy

1 2

input

Copy

31 1 1

output

Copy

-1

Note

In the first two samples the required pairs obviously don't exist.

In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.

大致题意为:

给出一个单调的序列,减缓两个不同的数,使它不单调。

直接暴力即可。

#include 
#include
#include
using namespace std;int a[100005],a1[100005],a2[100005];bool cmp(int x,int y){ return x>y;}int check(int *ch_a,int *ch_aa,int nn){ for(int i=1;i<=nn;i++) { if(ch_a[i]!=ch_aa[i]) return 0; } return 1;}int main(){ int n; while(cin>>n) { for(int i=1;i<=n;i++) { cin>>a[i]; a1[i]=a[i]; a2[i]=a[i]; } sort(a1+1,a1+n+1); sort(a2+1,a2+n+1,cmp); int ch1=check(a,a1,n),ch2=check(a,a2,n); int t,ok=0; if(ch1==1&&ch2==1) { cout<<"-1"<

 

转载地址:http://ymyzi.baihongyu.com/

你可能感兴趣的文章
1032 挖掘机技术哪家强 (20 分)
查看>>
Dividing HDU - 1059 ( 多重背包 - 二进制简化 )
查看>>
Robberies HDU - 2955 ( 0-1背包 )
查看>>
FATE HDU - 2459 ( 二维完全背包 )
查看>>
B. Working out CodeForces - 429B (动态规划)
查看>>
10635 - Prince and Princess UVA-10635 (最长公共子序列的O(nlogn)的解法:LCS转换为LIS)
查看>>
Sizeof和Strlen
查看>>
lower_bound和upper_bound
查看>>
Subsequence POJ - 3061 ( 尺取法 )
查看>>
常见HTTP状态码大全
查看>>
这16个数据可视化案例,惊艳了全球数据行业
查看>>
大数据死亡率报告揭秘:SUV与轿车到底谁更危险?
查看>>
2017年网络流行语TOP20 , 没用过算我输!
查看>>
看完这13张图,不得不佩服还是外国人会玩人工智能
查看>>
从零开始用Python构造决策树(附公式、代码)
查看>>
精华 | 12个关键词告诉你告诉你什么是机器学习(基础篇)
查看>>
15个优秀的开源项目,让你轻松应对Android开发
查看>>
正态分布为什么常见?
查看>>
大数据下的帝都魔都的爱恨情仇
查看>>
GitHub最著名的20个Python机器学习项目!
查看>>