Antiarithmetic?


E -design-easy
Crawling in process... Crawling failed
Time Limit: 3000MS     Memory Limit: 0KB     64bit IO Format: %lld & %llu

Description

Problem D: Antiarithmetic?

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 byn distinct numbers separated by whitespace. All n numbers are natural numbers smaller thann.

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

Output for sample input

yes
no
yes

Piotr Rudnicki


记下位置来求等差数列。
#include<stdio.h>
int z[10007];
int main()
{
    int m;
    while(scanf("%d: ",&m),m)
    {
        int n,t,flag=0;
        for(int a=0; a<m; a++)
        {
            scanf("%d",&t);
            z[t]=a;//记下位置
        }
        for(int b=0; b<m; b++)
        {
            for(int c=1; 2*c+b<m; c++)
            {
                if(z[b]<z[b+c]&&z[b+c]<z[b+2*c])//比较是否是等差数列
                {
                    printf("no\n");
                    flag=1;
                }
                if(flag==1)break;
            }
            if(flag==1)break;
        }
        if(!flag)printf("yes\n");

    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值