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).
![](http://codeforces.ru/renderer/17955cea517502d4201c4c3e899ac4043379ef7b.png)
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
output
input
output
Note
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
直接暴力就可以了!
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).
![](http://codeforces.ru/renderer/17955cea517502d4201c4c3e899ac4043379ef7b.png)
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; }
相关文章推荐
- Codeforces Round #208 (Div. 2) Problem A Dima and Continuous Line(暴力)
- Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
- Codeforces Round #208 (Div. 2) Problem A - Dima and Continuous Line
- CF10月25日比赛。(Dima and Continuous Line)
- A. Dima and Continuous Line
- A. Dima and Continuous Line----思维题
- CodeForces 358A - Dima and Continuous Line(模拟)
- A. Dima and Continuous Line
- Codeforces —— 358A Dima and Continuous Line
- CF10月25日比赛。(Dima and Continuous Line)
- Codeforces_358A_Dima and Continuous Line(排序+暴力)
- Codeforces Round #214 (Div. 2) C. Dima and Salad 背包
- Codeforces 584 D. Dima and Lisa ( Codeforces Round #324 (Div. 2))
- Codeforces Round #214 (Div. 2)——Dima and Salad
- Codeforces Round #208 (Div. 2) Problem B Dima and Text Messages(简单字符串处理)
- Codeforces #262 (Div. 2) B. Little Dima and Equation(数学:简单)
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- CF round167 Div1 C Dima and Horses
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima