If there are no sub-sequences of three elements in the sequence that constitute an equal difference, the output is yes or no.
Mark the position where each number appears, and start from 0 to find the three-element arithmetic difference series. If the positions of the three elements meet the conditions, there is an arithmetic difference series in the original series.
#include<cstdio>#include<cstring>int n,num[10010];int main(){ int n; while(scanf("%d",&n) == 1 && n) { getchar(); for(int i = 0; i < n; i++) { int a; scanf("%d",&a); num[a] = i; } int flag = 0; for(int i = 0; i < n; i++) { for(int j = 1; 2*j+i < n; j++) { if(num[i] < num[i+j] && num[i+j] < num[i+2*j]) { flag = 1; puts("no"); } else if(num[i] > num[i+j] && num[i+j] > num[i+2*j]) { flag = 1; puts("no"); } if(flag) break; } if(flag) break; } if(!flag) puts("yes"); } return 0;}