UVA - 10730

UVA - 10730

题目介绍:
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.

大意:
在n个数中能不能找出长度大于2的等差数列。枚举3个10000根据感觉不行。知道两个数,第三个数即可算出来。因此只要枚举2个数,判断算出的第三个数在不在第二个数之后。要判断是否在后面可以用图的方法。在最开始给定在i位置的数可以到达j处(j>i).

AC代码:

#include<iostream>
#include<cstring>
using namespace std;

int Link[10005][10005];

int main(){
	string que;
	while(cin>>que&&que!="0"){
		int n=0;
		for(int i=0;que[i]!=':';i++)
			if(isdigit(que[i]))
				n=n*10+que[i]-'0';
		int num[10005];
		for(int i=0;i<n;i++)
			scanf("%d",&num[i]);
		memset(Link,0,sizeof(Link));
		for(int i=0;i<n;i++)
			for(int j=i+1;j<n;j++)
				Link[num[i]][num[j]]=1;
		int ok=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				int c=num[j]+num[j]-num[i];
				if(c>=0&&c<n&&Link[num[j]][c]){
					ok=1;
					break;
				}
			}
			if(ok)break;
		}
		printf("%s\n", ok==1 ? "no" : "yes");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值