您的位置:首页 > 其它

Codeforces Round #208 (Div. 2) A. Dima and Continuous Line

2013-10-27 14:21 381 查看
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 <stdio.h>
#include <string.h>
using namespace std;
#define  M 10050
struct node {
int x,y;
}l[M];
int pri[M];
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
scanf("%d",&pri[i]);
bool flag=true;
for(i=0;i<n-1;i++){
l[i].x=pri[i];l[i].y=pri[i+1];
if(l[i].x>l[i].y)
swap(l[i].x,l[i].y);
for(int j=0;j<i;j++){
if(l[i].x>l[j].x&&l[i].x<l[j].y&&l[i].y>l[j].y){
flag=false;break;
}
if(l[i].x<l[j].x&&l[i].y<l[j].y&&l[i].y>l[j].x){
flag=false;break;
}
}
}
if(!flag)printf("yes\n");
else printf("no\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: