• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #208 Div.2 A

A. Dima and Continuous Line

time limit per test 2 seconds
memory limit per test256 megabytes
 
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.

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 #define maxn 1005
13 #define mod 1000000007
14 #define ll long long
15 #define INF 0x7fffffff
16 int n, m;
17 int p[maxn];
18 int main(){
19     int cas = 1;
20     int t;
21     /*scanf("%d", &t);
22     while (t--){
23         
24     }*/
25     while (~scanf("%d", &n)){
26         for(int i=0;i<n;i++)scanf("%d", &p[i]);
27         int flag=1,a, b, c, d;
28         for (int i = 0; i < n-1; i++)
29         for (int j = 0; j<n - 1;j++){
30             a = min(p[i], p[i + 1]);
31             b = max(p[i], p[i + 1]);
32             c = min(p[j], p[j + 1]);
33             d = max(p[j], p[j + 1]);
34             if (c>a&&c<b&&d>b || c<a&&d>a&&d < b){
35                 printf("yes\n"); flag = 0; i = n; j = n;
36             }
37         }
38         if(flag)printf("no\n");
39     }
40     return 0;
41 }
View Code 2013-10-26 08:51:28
posted @ 2013-10-26 08:51  HaibaraAi  阅读(186)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3