Codeforces Round #208 (Div. 2) A. Dima and Continuous Line
来源:互联网 发布:工业机器人控制软件 编辑:程序博客网 时间:2024/05/01 21:59
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.
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.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
40 10 5 15
yes
40 15 5 10
no
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 10050struct 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) 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
- A. Dima and Continuous Line
- A. Dima and Continuous Line
- Codeforces 358A - Dima and Continuous Line 暴力+数学
- Codeforces —— 358A Dima and Continuous Line
- CodeForces 358A - Dima and Continuous Line(模拟)
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
- A. Dima and Continuous Line----思维题
- Codeforces Round #208 (Div. 2) D. Dima and Hares
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2) C. Dima and Containers
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2)D. Dima and Hares
- Codeforces Round #208 (Div. 2)E. Dima and Kicks
- Codeforces Round #208 (Div. 2) Dima and Text Messages
- JAVA中的foreach循环
- 虚拟机增加新硬盘和vim显示行号
- PSCollectionView瀑布流实现
- visual studio 2010 运行后 不显示按任意键退出,窗口直接消失
- Winsock I/O方法
- Codeforces Round #208 (Div. 2) A. Dima and Continuous Line
- 计算机网络笔试题
- switch语句分段函数求值
- 2014年计算机求职总结--准备篇
- MySQL数据库锁介绍
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- 动态库简介
- switch语句构造菜单
- UVa 11294 Wedding (two SAT 输出解)