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).
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/21/6d40922dc20979714510e1fb77e19770.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.
题目理解:
大概意思是说,一个线段上按照一定的顺序给定n个点,会有(n-1)条线段生成,判断这些线段是否会有交点。有则输出yes,否则输出no。
代码:
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).
![](https://oscdn.geek-share.com/Uploads/Images/Content/202001/21/6d40922dc20979714510e1fb77e19770.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.
题目理解:
大概意思是说,一个线段上按照一定的顺序给定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; }
相关文章推荐
- CF10月25日比赛。(Dima and Continuous Line)
- CF10月25日比赛。(Dima and Text Messages)
- CF10月25日比赛。(Dima and Text Messages)
- 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
- Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
- Codeforces_358A_Dima and Continuous Line(排序+暴力)
- A. Dima and Continuous Line
- CodeForces 358A - Dima and Continuous Line(模拟)
- Codeforces Round #208 (Div. 2) Problem A Dima and Continuous Line(暴力)
- A. Dima and Continuous Line----思维题
- Codeforces —— 358A Dima and Continuous Line
- cf-Round #214 (Div. 2)-D-Dima and Trap Graph-dfs+二分
- CF 366E Dima and Magic Guitar(最远哈密顿距离)
- cf-366C-Dima and Salad
- CF 358C C. Dima and Containers 离线+模拟
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
- CF 366E - Dima and Magic Guitar 最远曼哈顿距离
- cf 167.div2 E.Dima and Horses