A. Dima and Continuous Line

A. Dima and Continuous Line
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.

The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).

Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

Input

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

Output

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

Sample test(s)
input
4
0 10 5 15
output
yes
input
4
0 15 5 10
output
no
Note

The first test from the statement is on the picture to the left, the second test is on the picture to the right.

/*#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
	bool key = false;
	int n;
	long r[1200];
	scanf("%d",&n);
	for(int i(0); i<n; i++)
	{
		cin >> r[i];
	}
	for(int i(2); i<n; i++)
	{
		if((r[i-1] > r[i-2] && r[i] < r[i-2] ) || (r[i-1] < r[i-2] && r[i] > r[i-2]) || r[i-1] == r[i-2])key = true;
	}
	cout << (key == true? "yes":"no") << endl;
	return 0;
}
*/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;

int main()
{
    int n,i,x=0,y=0,j;
    long a[1000];
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		x=y=0;
		for(j=i+2;j<n;j++) 
		{
			if ((a[j]>a[i]&&a[j]>a[i+1])||(a[j]<a[i]&&a[j]<a[i+1]))
			{
				x++;
			}
			else
			{
				y++;
			}
		}
		if(x&&y)
		{
			printf("yes\n");
			return 0;
		}
	}
	printf("no\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值