21335_Antiarithmetic_

2022-5-16 18:19| 发布者: Hocassian| 查看: 32| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505164650700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21335

Title

Antiarithmetic?

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21335

AC

3

Submit

5

Ratio

60.00%

时间&空间限制

  • Time Limit: 400/200 MS (Java/Others)     Memory Limit: 65536/65535 K (Java/Others)
  • 描述

    A permutation of n is a bijective function of the initial n natural numbers: 0, 1, ... n-1. A permutation p is called antiarithmetic if there is no subsequence of it forming an arithmetic progression of length bigger than 2, i.e. there are no three indices 0 ≤ i < j < k < n such that (pi , pj , pk) forms an arithmetic progression.

    For example, the sequence (2, 0, 1, 4, 3) is an antiarithmetic permutation of 5. The sequence (0, 5, 4, 3, 1, 2) is not an antiarithmetic permutation as its first, fifth and sixth term (0, 1, 2) form an arithmetic progression; and so do its second, forth and fifth term (5, 3, 1).

    Your task is to check whether a given permutation of n is antiarithmetic.

    输入

    There are several test cases, followed by a line containing 0. Each test case is a line of the input file containing a natural number 3 ≤ n 10000 followed by a colon and then followed by n distinct numbers separated by whitespace. All n numbers are natural numbers smaller than n.

    输出

    Description

    A permutation of n is a bijective function of the initial n natural numbers: 0, 1, ... n-1. A permutation p is called antiarithmetic if there is no subsequence of it forming an arithmetic progression of length bigger than 2, i.e. there are no three indices 0 ≤ i < j < k < n such that (pi , pj , pk) forms an arithmetic progression.

    For example, the sequence (2, 0, 1, 4, 3) is an antiarithmetic permutation of 5. The sequence (0, 5, 4, 3, 1, 2) is not an antiarithmetic permutation as its first, fifth and sixth term (0, 1, 2) form an arithmetic progression; and so do its second, forth and fifth term (5, 3, 1).

    Your task is to check whether a given permutation of n is antiarithmetic.

    Input

    There are several test cases, followed by a line containing 0. Each test case is a line of the input file containing a natural number 3 ≤ n 10000 followed by a colon and then followed by n distinct numbers separated by whitespace. All n numbers are natural numbers smaller than n.

    Output

    For each test case output one line with yes or no stating whether the permutation is antiarithmetic or not.

    Sample Input
    3: 0 2 1
    5: 2 0 1 3 4
    6: 2 4 3 5 0 1
    0
    Sample Output
    yes
    no
    yes
    Source

    样例输入

    3: 0 2 1
    5: 2 0 1 3 4
    6: 2 4 3 5 0 1
    0

    样例输出

    yes
    no
    yes

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部