若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1182: Antiarithmetic?

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,179

题目描述

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.
For each test case output one line with yes or no stating whether the permutation is antiarithmetic or not.

输入

Please Input Input Here

输出

Please Input Output Here

样例输入

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

样例输出

yes
no
yes

参考代码

#include <stdio.h>
int main() 
{
    int n,i,k=0,j,nn[10001],f[10001];
    while(scanf("%d:",&n)) 
    {
        if(n==0)break;
        for (i=0;i<n;i++) 
        {
            scanf("%d",&f[i]);
        }
        for (i=0;i<n;i++) 
        {
            nn[f[i]]=i;
        }
        for (i=0;k!=1&&i<n-1;i++) 
        {
            for (j=i+1;k!=1&&j<n;j++) 
            {
                if(2*j-i>=n) 
                {
                    break;
                }
                if((nn[i]<nn[j])&&(nn[j]<nn[2*j-i])) 
                {
                    printf("non");
                    k=1;
                }
                if((nn[i]>nn[j])&&(nn[j]>nn[2*j-i]))
                {printf("non");
                    k=1;
                }
            }
        }
        if(k==0)
        {
            printf("yesn");
        }
        k=0;
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Skip Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist