Hello World

查看题解 查看答案
题目描述
Time Limit: 1000 ms
Memory Limit: 256 mb

Sorry, maybe the topic is different from what you think.

Ms.D has a habit of saving money, and she is a man with a plan, so she makes a schedule for herself to save money.

From the first day, the amount of money deposited each day is the same as the number of days, such as $3 on day 3,  $10 on day 10...

Ms. D was very happy with her plan, but her friend Mr. X wanted to tease her, so Mr. X secretly changed her plan.

Mr. X would pick an interval [l, r] and reverse it. At that the segment's endpoints did not coincide.

For example, if n = 5,Ms. D’s plan should be saved in order 1 2 3 4 5.if Mr. X chose the segment[2,4],  then after the reversal the plan order will change to 1 4 3 2 5.

Mr.X suspects that someone else could have spoilt the permutation after Ms.D. Help him to find that out. 

Check if the given permutation can be obtained from the permutation 1 2 ... n using exactly one segment reversal. If it is possible, find the segment itself.

输入输出格式
输入描述:
The first line contains an integer n (1 <= n <= 1000) ——Indicates the number of days planned. The second line contains space-separated n integers which are the spoilt sequence of plans. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.
输出描述:
If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 <= l <= r <= n)which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.
输入输出样例
输入样例#:
7
2 3 4 5 6 7 1
10
1 2 3 7 6 5 4 8 9 10
5
1 2 3 4 5
输出样例#:
复制
0 0
4 7
0 0
编辑器外观×
主题
字号 16px
背景
登录后免费刷此题

提交代码后在此处可查看状态