您的位置:首页 > 其它

CF10月25日比赛。(Dima and Continuous Line)

2015-01-05 13:01 567 查看
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.
题目理解:
   大概意思是说,一个线段上按照一定的顺序给定n个点,会有(n-1)条线段生成,判断这些线段是否会有交点。有则输出yes,否则输出no。
代码:
   

#include <stdio.h>
#include <string.h>
/*
CF第一题:判断n-1条线段是否有交点。
*/
#define N 1010
typedef struct
{
int a,b;
}LNode;
LNode q
;
int min(int a,int b){return a>b? b:a;}
int max(int a,int b){return a>b? a:b;}
int panduan(LNode a,LNode b)
{
//判断a,b是否有交点;
int mi1,mi2,ma1,ma2;
mi1=min(a.a,a.b);ma1=max(a.a,a.b);
mi2=min(b.a,b.b);ma2=max(b.a,b.b);
if((mi2>mi1&&mi2<ma1&&ma2>ma1)||(mi2<mi1&&ma2>mi1&&ma2<ma1)) return 1;
else return 0;

}
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
int a,b;j=0;
scanf("%d",&a);
for(i=1;i<n;i++)
{
scanf("%d",&b);
q[j].a=a;q[j++].b=b;
a=b;
}
int ok=0;
for(i=0;i<n-1;i++)
for(j=i+1;j<n-1;j++)
if(i!=j)
if(panduan(q[i],q[j])) {ok=1;break;}

if(ok) printf("yes\n");
else printf("no\n");
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: