Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
struct circle {
int x;
int d;
} c[1005];
int main() {
int i, j, flag, n, a[1005];
scanf("%d", &n);
flag = 0;
for (i = 0; i < n; ++i) scanf("%d", &a[i]);
for (i = 0; i < n - 1; ++i) {
c[i].x = min(a[i], a[i + 1]);
c[i].d = abs(a[i + 1] - a[i]);
}
for (i = 0; i < n - 2; ++i) {
for (j = i + 1; j < n - 1; ++j) {
if (c[i].x < c[j].x) {
if ((c[j].x - c[i].x < c[i].d) && (c[i].x + c[i].d < c[j].x + c[j].d)) {
flag = 1;
break;
}
} else if (c[i].x > c[j].x) {
if ((c[i].x - c[j].x < c[j].d) && (c[j].x + c[j].d < c[i].x + c[i].d)) {
flag = 1;
break;
}
}
}
if (flag) break;
}
if (!flag)
printf("no\n");
else
printf("yes\n");
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader fs=new FastReader();
int n = fs.nextInt();
List<int[]> ls = new ArrayList<int[]>();
int[] a = new int[n];
for(int i=0;i<n;i++)
{
a[i] = fs.nextInt();
}
boolean flag = false;
for(int i=0;i<n-1;i++)
{
int l = Math.min(a[i],a[i+1]);
int r = Math.max(a[i],a[i+1]);
for(int[] ar : ls)
{
if( ( (ar[0]<l && ar[0]<r) && (ar[1]>l && ar[1]<r) ) || ( (ar[0]>l && ar[0]<r) && (ar[1]>l && ar[1]>r) ) )
{
flag=true;
break;
}
}
ls.add(new int[]{l,r});
if(flag)
break;
}
String res = (flag) ? "yes" : "no";
System.out.println(res);
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
def solver():
n = input()
num = map(int,raw_input().split())
for i in range(len(num)-1):
x1 = num[i]
y1 = num[i+1]
left = min(x1,y1)
right = max(x1,y1)
for j in range(i+1,len(num)-1):
x2 = num[j]
y2 = num[j+1]
now_left = min(x2,y2)
now_right = max(x2,y2)
if left == now_left and right == now_right:
print "yes"
return
if left == now_left or right == now_right:
continue
if left < now_left < right and right < now_right:
print "yes"
return
if left < now_right < right and left > now_left:
print "yes"
return
print "no"
if __name__ == "__main__":
solver()
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[1005];
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= n; j++) {
if (i == j) continue;
int x1 = a[i - 1];
int y1 = a[i];
int x2 = a[j - 1];
int y2 = a[j];
if (x1 > y1) swap(x1, y1);
if (x2 > y2) swap(x2, y2);
if (x2 > x1 && x2 < y1 && y2 > y1) {
printf("yes\n");
return 0;
}
if (x1 > x2 && x1 < y2 && y1 > y2) {
printf("yes\n");
return 0;
}
}
}
printf("no\n");
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = 1 + i; j < n - 1; j++) {
int p = a[i], q = a[i + 1], r = a[j], s = a[j + 1];
if (p > q) swap(p, q);
if (r > s) swap(r, s);
if (r > p && r < q && s > q || s > p && s < q && r < p) {
cout << "yes";
return;
}
}
}
cout << "no";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.*;
import java.util.*;
public class DimaAndContinuousLine {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
StringTokenizer st = new StringTokenizer(f.readLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = Integer.parseInt(st.nextToken());
boolean intersect = false;
for (int i = 0; i < n-1; i++)
for (int j = i+1; j < n-1; j++) {
int x = Math.min(a[i], a[i+1]);
int y = Math.max(a[i], a[i+1]);
if (a[j] > x && a[j] < y)
if (a[j+1] < x || a[j+1] > y)
intersect = true;
if (a[j] < x || a[j] > y)
if (a[j+1] > x && a[j+1] < y)
intersect = true;
}
System.out.println(intersect?"yes":"no");
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.*;
import java.util.*;
public class Semicircles {
public static void main(String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(rd.readLine());
x = new int[n];
st = new StringTokenizer(rd.readLine());
for(int i=0; i<n; i++) x[i] = Integer.parseInt(st.nextToken());
if(n<=2){
System.out.println("no");
return;
}
for(int i=0; i<n-1; i++){
if(!ok(x[i], x[i+1], i)){
System.out.println("yes");
return;
}
}
System.out.println("no");
}
static boolean ok(int a, int b, int iter){
for(int i=0; i<iter; i++){
if(intersect(a, b, x[i], x[i+1]))
return false;
}
return true;
}
static boolean intersect(int x, int y, int a, int b){
if(x>y || a>b) return intersect(Math.min(x, y), Math.max(x, y), Math.min(a, b), Math.max(a, b));
return (x<a && a<y && b>y) || (a<x && x<b && y>b);
}
static int[] x;
static boolean[][] been = new boolean[1001][1001];
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] a = new int[n];
boolean yes = false;
for (int i = 0; i < n && !yes; i++) {
a[i] = in.nextInt();
for (int j = 1; j < i; j++) {
int[] x = { a[i - 1], a[i], a[j - 1], a[j] };
Arrays.sort(x, 0, 2);
Arrays.sort(x, 2, 4);
yes |= (x[0] < x[2] && x[2] < x[1] && x[1] < x[3]) || (x[2] < x[0] && x[0] < x[3] && x[3] < x[1]);
}
}
System.out.println(yes ? "yes" : "no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(raw_input())
a = map(int, raw_input().split())
ok = True
b = [[a[i], a[i+1]] for i in xrange(n-1)]
for i in xrange(n-1):
b[i].sort()
for j in xrange(i):
if b[i][0] < b[j][0] < b[i][1] < b[j][1] or b[j][0] < b[i][0] < b[j][1] < b[i][1]:
ok = False
print "no" if ok else "yes"
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
l=list(map(int,input().split()))
l1=[]
for i in range(n-1):
l1+=[[l[i],l[i+1]]]
for i in range(n-1):
if l1[i][0]>l1[i][1]:
l1[i][0],l1[i][1]=l1[i][1],l1[i][0]
for i in l1:
for j in l1:
if i[0]<j[0]<i[1]<j[1]:
print("yes")
exit()
elif j[0]<i[0]<j[1]<i[1]:
print("yes")
exit()
print("no") | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n,ans = int(raw_input()),"no"
x = list(int(y) for y in raw_input().split())
for i in xrange(0,n-1):
for j in xrange(0,i):
l,r = sorted([x[i],x[i+1]])
L,R = sorted([x[j],x[j+1]])
if l>L and l<R and r>R : ans = "yes"
elif r>L and r<R and l<L : ans = "yes"
print ans
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | a=int(input())
z=[]
te=list(map(int,input().split()))
for i in range(1,len(te)):
z.append([min(te[i],te[i-1]),max(te[i],te[i-1])])
flag=0
for i in range(len(z)):
for j in range(i+1,len(z)):
if(z[j][0]<z[i][0]<z[j][1] and z[i][1]>z[j][1]):
flag=1
break;
if(z[i][0]<z[j][0]<z[i][1] and z[j][1]>z[i][1]):
flag=1
break;
if(flag==1):
print('yes')
else:
print('no')
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, now, prev;
vector<pair<int, int> > e;
cin >> n >> prev;
for (int i = 1; i < n; ++i) {
cin >> now;
e.push_back(pair<int, int>(min(prev, now), max(prev, now)));
prev = now;
}
sort(e.begin(), e.end());
for (unsigned i = 0; i < e.size(); ++i) {
for (unsigned j = i + 1; j < e.size(); ++j) {
if (e[j].first > e[i].first && e[j].first < e[i].second &&
e[j].second > e[i].second) {
cout << "yes\n";
return 0;
}
}
}
cout << "no\n";
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
vector<int> store;
int n;
cin >> n;
for (int k = 0; k < n; k++) {
int curr;
cin >> curr;
store.push_back(curr);
}
vector<pair<int, int>> pairs;
for (int k = 0; k < store.size() - 1; k++)
pairs.push_back(
make_pair(min(store[k], store[k + 1]), max(store[k], store[k + 1])));
bool ans = false;
for (int k = 0; k < store.size() - 1; k++) {
for (int j = k + 1; j < store.size(); j++) {
if (get<0>(pairs[k]) < get<0>(pairs[j]) &&
get<0>(pairs[j]) < get<1>(pairs[k]) &&
get<1>(pairs[k]) < get<1>(pairs[j]))
ans = true;
else if (get<0>(pairs[j]) < get<0>(pairs[k]) &&
get<0>(pairs[k]) < get<1>(pairs[j]) &&
get<1>(pairs[j]) < get<1>(pairs[k]))
ans = true;
}
}
if (ans)
cout << "yes";
else
cout << "no";
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author naman
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
cf_208_A solver = new cf_208_A();
solver.solve(1, in, out);
out.close();
}
}
class cf_208_A {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n=in.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=in.nextInt();
int a_start,a_end,b_start,b_end;
boolean status=false;
for(int i=0;i<n-1;i++)
{
a_start=Math.min(a[i],a[i+1]);
a_end=Math.max(a[i],a[i+1]);
for(int j=i+1;j<n-1;j++)
{
b_start=Math.min(a[j],a[j+1]);
b_end=Math.max(a[j],a[j+1]);
if((a_start<b_start && b_start<a_end && a_end<b_end) || (b_start<a_start && b_end>a_start && b_end<a_end))
{
status=true;
//out.printLine("yes");
break;
}
}
}
if(status)
out.printLine("yes");
else
out.printLine("no");
}
}
class InputReader
{
BufferedReader in;
StringTokenizer tokenizer=null;
public InputReader(InputStream inputStream)
{
in=new BufferedReader(new InputStreamReader(inputStream));
}
public String next()
{
try{
while (tokenizer==null||!tokenizer.hasMoreTokens())
{
tokenizer=new StringTokenizer(in.readLine());
}
return tokenizer.nextToken();
}
catch (IOException e)
{
return null;
}
}
public int nextInt()
{
return Integer.parseInt(next());
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
bool intersectan(int a, int b, int c, int d) {
if (a > b) swap(a, b);
if (c > d) swap(c, d);
if ((a < c && c < b && b < d) || (c < a && a < d && d < b)) {
return true;
}
return false;
}
int main() {
int n;
bool e = false;
cin >> n;
vector<int> x(n);
cin >> x[0];
for (int i = 1; (i < n); i++) {
cin >> x[i];
for (int j = 0; (j < i - 2); j++) {
if (intersectan(x[i - 1], x[i], x[j], x[j + 1])) e = true;
}
}
if (e)
cout << "yes" << endl;
else
cout << "no" << endl;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = input()
v = list(map(int, raw_input().split()))
w = [(min(v[x], v[x+1]), max(v[x], v[x+1])) for x in range(0, n-1)]
for i in range(0, len(w)):
for j in range(0, len(w)):
if i == j: continue
a, b = w[i][0], w[i][1]
c, d = w[j][0], w[j][1]
if a < c and c < b and (d < a or d > b):
print 'yes'
exit()
print 'no'
#####
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int cmp(vector<int> x, vector<int> y) { return x[0] < y[0]; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(3));
multiset<pair<int, int>> stl, str;
int prev;
cin >> prev;
for (int i = 1; i < n; ++i) {
int cur;
cin >> cur;
a[i][0] = abs(cur - prev);
a[i][1] = min(cur, prev);
a[i][2] = max(cur, prev);
stl.insert(make_pair(min(cur, prev), max(cur, prev)));
str.insert(make_pair(max(cur, prev), min(cur, prev)));
prev = cur;
}
bool ok = true;
sort(a.begin(), a.end(), cmp);
for (int i = 1; i < n; ++i) {
multiset<pair<int, int>>::iterator it;
it = stl.lower_bound(make_pair(a[i][1] + 1, 0));
if (a[i][0] > 1) {
if (it != stl.end()) {
if (it->first < a[i][2]) {
ok = false;
break;
}
}
if (!ok) break;
it = str.lower_bound(make_pair(a[i][2] + 1, 0));
if (it != str.end()) {
if (it->first < a[i][1]) {
ok = false;
break;
}
}
if (!ok) break;
}
it = stl.find(make_pair(a[i][1], a[i][2]));
stl.erase(it);
it = str.find(make_pair(a[i][2], a[i][1]));
str.erase(it);
}
if (ok)
cout << "no";
else
cout << "yes";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.*;
import java.io.*;
import java.util.Scanner;
public class luckydivision {
public static void main(String args[]){
Scanner inp = new Scanner(System.in);
int n = inp.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;++i){
arr[i] = inp.nextInt();
}
int flag = 0;
for(int i=0;i<n-1;i++){
if(flag == 1){
break;
}
for(int j=0;j<n-1;j++){
if((Math.min(arr[i], arr[i+1])<Math.min(arr[j], arr[j+1]) && Math.min(arr[j], arr[j+1])<Math.max(arr[i], arr[i+1]) &&
Math.max(arr[i], arr[i+1])<Math.max(arr[j], arr[j+1])) || (Math.min(arr[j], arr[j+1])<Math.min(arr[i], arr[i+1]) && Math.min(arr[i], arr[i+1])<Math.max(arr[j], arr[j+1]) &&
Math.max(arr[j], arr[j+1])<Math.max(arr[i], arr[i+1]))){
System.out.print("yes");
flag = 1;
break;
}
}
}
if(flag == 0){
System.out.print("no");
}
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | ######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip()) # for strings to list of char
from collections import defaultdict as df
import heapq
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
infinite = float('inf')
#######################################################################
def swap(a,b):
t=a
a=b
b=t
n=int(input())
l=RI()
s=[]
for i in range(n-1):
s.append((l[i],l[i+1]))
f=0
for i in range(n-1):
for j in range(n-1):
if(i==j):
continue
x1,x2=s[i]
if(x2<x1):
x1,x2=x2,x1
x3,x4=s[j]
if(x4<x3):
x3,x4=x4,x3
if((x1<x3 and x3<x2 and x2<x4) or (x3<x1 and x1<x4 and x2>x4)):
f=1
break
if(f==1):
break
#print(i)
if(f==0):
print("no")
else:
print("yes")
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > v;
vector<int> num;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
num.push_back(a);
if (i > 0) {
int b = num[i - 1];
v.push_back(make_pair(min(a, b), max(a, b)));
}
}
for (int i = 0; i < v.size(); i++) {
for (int x = 0; x < v.size(); x++) {
if (i == x) continue;
pair<int, int> p1 = v[i];
pair<int, int> p2 = v[x];
if (p1.first < p2.first && p1.second < p2.second &&
p1.second > p2.first) {
cout << "yes" << endl;
return 0;
}
if (p2.first < p1.first && p2.second < p1.second &&
p2.second > p1.first) {
cout << "yes" << endl;
return 0;
}
}
}
cout << "no" << endl;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.awt.Point;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class DimaAndContinuousLine {
void run() throws Exception {
BufferedReader bfd = new BufferedReader(
new InputStreamReader(System.in));
int n = Integer.parseInt(bfd.readLine());
int[] arr = new int[n];
StringTokenizer tk = new StringTokenizer(bfd.readLine());
for (int i = 0; i < arr.length; ++i)
arr[i] = Integer.parseInt(tk.nextToken());
boolean inter = false;
ML : for (int i = 0; i < arr.length - 1; ++i) {
int mnI = Math.min(arr[i], arr[i + 1]);
int mxI = Math.max(arr[i], arr[i + 1]);
Point i1 = new Point(mnI, mxI);
for (int j = 0; j < arr.length - 1; ++j) {
int mnJ = Math.min(arr[j], arr[j + 1]);
int mxJ = Math.max(arr[j], arr[j + 1]);
Point i2 = new Point(mnJ, mxJ);
if (intersect(i1, i2)) {
inter = true;
break ML;
}
}
}
if (inter)
System.out.println("yes");
else
System.out.println("no");
}
private boolean intersect(Point p1, Point p2) {
if ((p2.x > p1.x && p2.x < p1.y && p2.y > p1.y)
|| (p2.y > p1.x && p2.y < p1.y && p2.x < p1.x))
return true;
return false;
}
public static void main(String[] args) throws Exception {
new DimaAndContinuousLine().run();
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1111];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++)
for (int j = i + 1; j + 1 < n; j++) {
int u = min(a[i], a[i + 1]), v = max(a[i], a[i + 1]);
int uu = min(a[j], a[j + 1]), vv = max(a[j], a[j + 1]);
if (u > uu) swap(u, uu), swap(v, vv);
if (uu > u && uu < v && v < vv) {
puts("yes");
return 0;
}
}
puts("no");
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
typedef struct node {
int data;
struct node *next;
} linklist;
linklist *last;
linklist *InitList() {
linklist *L;
L = (linklist *)malloc(sizeof(linklist));
L->next = L;
return L;
}
int InsSortItem(linklist *L, int item) {
int j;
linklist *p, *t;
p = L;
j = 1;
t = (linklist *)malloc(sizeof(linklist));
t->data = item;
while ((p->next != L) && (p->next->data < t->data)) {
p = p->next;
j++;
}
t->next = p->next;
p->next = t;
if (p == last || t->next == last) {
last = t;
return 1;
}
if (p == L && last->next == L) {
last = t;
return 1;
}
if (t->next == L && L->next == last) {
last = t;
return 1;
}
return 0;
}
int main() {
linklist *L;
int bo;
L = InitList();
last = L;
int t, x;
scanf("%d", &t);
bo = 0;
while (t--) {
scanf("%d", &x);
if (InsSortItem(L, x) == 0) bo = 1;
}
if (bo == 1)
printf("yes\n");
else
printf("no\n");
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import sys
import math
import itertools
import collections
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return int(str(n)[::-1])
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base=3):
newnumber = ''
while number > 0:
newnumber = str(number % base) + newnumber
number //= base
return newnumber
n = ii()
x = li()
if n < 4:
print('no')
else:
for i in range(n - 1):
l, r = min(x[i], x[i + 1]), max(x[i], x[i + 1])
for j in range(i + 2, n - 1):
lt, rt = min(x[j], x[j + 1]), max(x[j], x[j + 1])
if lt < l and l < rt and rt < r or l < lt and lt < r and r < rt:
exit(print('yes'))
print('no')
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 |
import java.io.*;
import java.util.StringTokenizer;
public class A implements Runnable {
PrintWriter out;
BufferedReader br;
StringTokenizer st;
public static void main(String[] args) throws IOException {
new Thread(new A()).start();
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new BufferedOutputStream(System.out));
solve();
out.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void solve() throws IOException {
int n = nextInt();
int[] a1 = new int[n];
for (int i = 0; i < n; ++i) {
a1[i] = nextInt();
}
for (int i = 1; i < n; ++i) {
int from = Math.min(a1[i - 1], a1[i]);
int to = Math.max(a1[i - 1], a1[i]);
for (int j = i; j < n - 1; ++j) {
int pFrom = Math.min(a1[j], a1[j + 1]);
int pTo = Math.max(a1[j], a1[j + 1]);
if (pTo <= from && pFrom <= from || pTo >= to && pFrom >= to || pFrom >= from && pTo <= to || from >= pFrom && to <= pTo){
} else {
out.println("yes");
return;
}
}
}
out.println("no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Main
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = Integer.parseInt(in.readLine());
StringTokenizer datos = new StringTokenizer(in.readLine());
List<Integer> points = new ArrayList<Integer>();
if(n<3){
System.out.println("no");
return;
}
points.add(Integer.parseInt(datos.nextToken()));
points.add(Integer.parseInt(datos.nextToken()));
points.add(Integer.parseInt(datos.nextToken()));
while(datos.hasMoreTokens()){
int p1 = points.get(points.size()-1);
int p2 = Integer.parseInt(datos.nextToken());
for(int i=0;i<points.size()-1;i++){
if(points.get(i+1)==p1) continue;
boolean b1 = inRange(points.get(i), points.get(i+1), p1);
boolean b2 = inRange(points.get(i), points.get(i+1), p2);
if(b1^b2){
System.out.println("yes");
return;
}
}
points.add(p2);
}
out.println("no");
out.flush();
}
public static boolean inRange(int a, int b,int p)
{
int a1 = Math.min(a, b);
int b1 = Math.max(a, b);
return p>=a1 && p<=b1;
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(raw_input())
l = map(int,raw_input().split())
def check(i,j):
a,b = min(l[i],l[i+1]),max(l[i],l[i+1])
c,d = min(l[j],l[j+1]),max(l[j],l[j+1])
return (a < c and c < b and b < d) or (c < a and a<d and d < b)
ans = "no"
for i in xrange(n-1):
for j in xrange(i+1,n-1):
if check(i,j):
ans = "yes"
print ans | PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Scanner;
import java.lang.*;
import static java.lang.Integer.max;
import static java.lang.Integer.min;
public class DimaandContinuousLine {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
boolean x=false;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
for(int i=0;i<n-1;i++) {
for (int j = 0; j < n - 1; j++) {
if ((min(a[i], a[i + 1]) < min(a[j], a[j + 1]) && min(a[j], a[j + 1]) < max(a[i], a[i + 1]) && max(a[i], a[i + 1]) < max(a[j], a[j + 1])) ||
(min(a[j], a[j + 1]) < min(a[i], a[i + 1]) && min(a[i], a[i + 1]) < max(a[j], a[j + 1]) && max(a[j], a[j + 1]) < max(a[i], a[i + 1]))) {
x = true;
}
}
}
if(x) System.out.println("yes");
else System.out.println("no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
ans = "no"
f = lambda x, y: x[0] < y[0] < x[1] < y[1] or \
y[0] < x[0] < y[1] < x[1]
xs = list(map(int, input().split()))
for i in range(1, len(xs) - 1):
for j in range(0, i):
if f([min(xs[i:i+2]), max(xs[i:i+2])], [min(xs[j:j+2]), max(xs[j:j+2])]):
ans = "yes"
break
print(ans) | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g;
int n, m[100000], a, b;
bool check(int x11, int x12, int x21, int x22) {
if (x21 < x12 && x22 > x12 && x11 < x21 ||
x21 < x11 && x22 > x11 && x12 > x22)
return true;
else
return false;
}
int main() {
scanf("%d", &n);
scanf("%d", &a);
for (int i = 1; i < n; i++) {
b = a;
scanf("%d", &a);
g.push_back(make_pair(min(a, b), max(a, b)));
for (int i = 0; i < g.size() - 1; i++)
if (check(g[i].first, g[i].second, min(a, b), max(a, b))) {
printf("yes\n");
return 0;
}
}
printf("no\n");
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 |
n = int(input())
x = list(map(int, input().split()))
x = [sorted(x[i:i+2]) for i in range(n-1)]
for c,d in x:
for a,b in x:
if a < c < b <d:
print("yes")
exit()
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T getabs(T n) {
return n < 0 ? -n : n;
}
template <class T>
T getmax(T a, T b) {
return (a > b ? a : b);
}
template <class T>
T getmin(T a, T b) {
return (a < b ? a : b);
}
template <class T>
void setmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return ((a * b) / gcd(a, b));
}
template <class T>
T power(T n, T p) {
if (p == 0) return 1;
return ((p == 1) ? n : (n * power(n, p - 1)));
}
vector<int> pset(1000);
void initSet(int _size) {
pset.resize(_size);
for (__typeof(_size) i = 0; i < (_size); i++) pset[i] = i;
}
int findSet(int i) { return (pset[i] == i) ? i : (pset[i] = findSet(pset[i])); }
void unionSet(int i, int j) { pset[findSet(i)] = findSet(j); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
int n;
void Solve() {
scanf("%d", &n);
if (n == 1) {
printf("no\n");
return;
}
vector<int> a(n);
for (__typeof(n) i = 0; i < (n); i++) scanf("%d", &a[i]);
bool yes = false;
for (int i = 0; i + 1 < n; i++) {
for (int j = i + 1; j + 1 < n; j++) {
int l1 = min(a[i], a[i + 1]), r1 = max(a[i], a[i + 1]);
int l2 = min(a[j], a[j + 1]), r2 = max(a[j], a[j + 1]);
if (!(l1 <= l2 && r2 <= r1 || l2 <= l1 && r1 <= r2) &&
!(r2 <= l1 || r1 <= l2)) {
yes = true;
}
}
}
printf("%s\n", yes ? "yes" : "no");
}
int main() {
Solve();
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | def main():
n = int(input())
l, a = [], 0
for b in map(int, input().split()):
l.append((a, b) if a < b else(b, a))
a = b
l[0] = ((9999999, 0))
l.sort()
del l[-1]
for i, (c, d) in enumerate(l):
for j in range(i):
a, b = l[j]
if a < c < b < d:
print('yes')
return
print('no')
if __name__ == '__main__':
main() | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
A=[int(x) for x in input().split()]
for i in range(n-1):
Main=[A[i],A[i+1]]
Main.sort()
for j in range(i+1,n-1):
SubMain=[A[j],A[j+1]]
SubMain.sort()
NewList=[Main,SubMain]
NewList.sort()
if NewList[0][0]==NewList[1][0]:
continue
elif NewList[0][1]>NewList[1][0] and NewList[1][1]>NewList[0][1]:
print("yes")
exit()
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[1015];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int intersec = 0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < n && abs(i - j) > 1; j++) {
int A = min(a[i], a[i + 1]), B = max(a[i], a[i + 1]);
int C = min(a[j], a[j + 1]), D = max(a[j], a[j + 1]);
if (A < C && C < B && B < D) intersec = 1;
if (C < A && A < D && D < B) intersec = 1;
}
}
cout << ((intersec == 1) ? "yes" : "no") << endl;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
points = list(map(int,input().split(" ")))
segments = []
for i in range(len(points)):
if i != len(points) - 1:
segments.append((points[i],points[i+1]))
r = "no"
for seg1 in segments:
for seg2 in segments:
if seg1==seg2:
continue
x1,x2,x3,x4 = (min(seg1),max(seg1),min(seg2),max(seg2))
if (x1<x3<x2<x4) or (x3<x1<x4<x2):
r = "yes"
break
print(r)
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class A {
//IO
static BufferedReader f;
static PrintWriter out;
static StringTokenizer st;
final public static void main( String[] args ) throws IOException {
f = new BufferedReader( new InputStreamReader( System.in ) );
out = new PrintWriter( System.out );
solve();
f.close();
out.close();
System.exit( 0 );
}
final public static void solve() throws IOException {
int N = nextInt();
Semicircle[] circles = new Semicircle[ N-1 ];
int lastPoint = nextInt();
for ( int i=1 ; i<N ; ++i ) {
int nextPoint = nextInt();
circles[ i-1 ] = new Semicircle( lastPoint , nextPoint );
lastPoint = nextPoint;
}
Arrays.sort( circles );
for ( int i=0 ; i<N-1 ; ++i ) {
for ( int j=i+1 ; j<N-1 ; ++j ) {
if ( circles[ i ].m_start < circles[ j ].m_start && circles[ j ].m_start < circles[ i ].m_end ) {
if ( circles[ j ].m_end > circles[ i ].m_end ) {
System.out.println( "yes" );
System.exit( 0 );
}
}
if ( circles[ j ].m_start < circles[ i ].m_end && circles[ i ].m_end < circles[ j ].m_end ) {
if ( circles[ j ].m_start < circles[ i ].m_start ) {
System.out.println( "yes" );
System.exit( 0 );
}
}
}
}
System.out.println( "no" );
System.exit( 0 );
}
static class Semicircle implements Comparable< Semicircle >{
public final int m_start;
public final int m_end;
public Semicircle( int start , int end ) {
if ( start > end ) {
int tmp = start;
start = end;
end = tmp;
}
this.m_start = start;
this.m_end = end;
}
@Override
public int compareTo(Semicircle arg0) {
return new Integer( this.m_start ).compareTo( arg0.m_start );
}
@Override
public String toString() {
return "(" + this.m_start + ", " + this.m_end + ")";
}
}
final public static String nextToken() throws IOException {
while ( st == null || !st.hasMoreTokens() ) {
st = new StringTokenizer( f.readLine() );
}
return st.nextToken();
}
final public static int nextInt() throws IOException {
return Integer.parseInt( nextToken() );
}
final public static long nextLong() throws IOException {
return Long.parseLong( nextToken() );
}
final public static double nextDouble() throws IOException {
return Double.parseDouble( nextToken() );
}
final public static boolean nextBoolean() throws IOException {
return Boolean.parseBoolean( nextToken() );
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
vector<long int> v;
int main() {
int i, j, n;
cin >> n;
long int k;
for (i = 0; i < n; i++) {
cin >> k;
v.push_back(k);
}
long int a, b;
int q = 0;
for (i = 0; i < v.size() - 1; i++) {
b = max(v[i], v[i + 1]);
a = min(v[i], v[i + 1]);
for (j = 0; j < v.size() - 1; j++) {
if (a < v[j] && v[j] < b) {
if (v[j + 1] < a || v[j + 1] > b) {
q++;
cout << "yes";
break;
}
}
if (a < v[j + 1] && v[j + 1] < b) {
if (v[j] < a || v[j] > b) {
q++;
cout << "yes";
break;
}
}
}
if (q > 0) {
break;
}
}
if (q == 0) {
cout << "no";
}
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int( input() )
l = [int(x) for x in input().split()]
found = False
if n<4:
print("no")
else:
for i in range(n-2):
a= min(l[i], l[i+1])
b= max(l[i], l[i+1])
for j in range(i+1, n-1, 1):
c=min(l[j], l[j+1])
d=max(l[j],l[j+1])
if c<a and a<d and b>d:
found = True
break
if c<b and b<d and a<c:
found = True
break
if found:
break
if found:
print("yes")
else:
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
x = [int(x) for x in input().split()]
p = x[0]
l = []
for i in range(1, n):
for a, b in l[:-1]:
if (a < x[i] < b) ^ (a < p < b):
print('yes')
exit()
l.append((min(p, x[i]), max(p, x[i])))
p = x[i]
print('no')
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 |
N = int(input())
array = list(map(int, input().split()))
points = []
for i in range(N - 1):
points.append(sorted((array[i], array[i+1])))
#print(points)
for i in points:
for j in points:
if i[0] < j[0] and j[1] > i[1] > j[0]:
#print(i, j)
print("yes")
exit(0)
print("no") | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Arrays;
import java.util.Scanner;
public class Young {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int tab[] = new int[n];
boolean res = false;
for(int i =0; i<n; i++)
{
tab[i] = sc.nextInt();
}
for(int i = 0; i<n-1 ; i++)
{
for(int j = i+2; j<n-1 ; j++)
{
if(tab[i] > Math.min(tab[j], tab[j + 1]) && tab[i] < Math.max(tab[j], tab[j + 1]))
if(tab[i + 1] < Math.min(tab[j], tab[j + 1]) || tab[i + 1] > Math.max(tab[j] , tab[j + 1]))
res = true;
if(tab[j] > Math.min(tab[i], tab[i + 1]) && tab[j] < Math.max(tab[i], tab[i + 1]))
if(tab[j + 1] < Math.min(tab[i], tab[i + 1]) || tab[j + 1] > Math.max(tab[i] , tab[i + 1]))
res = true;
if(tab[i + 1] > Math.min(tab[j], tab[j + 1]) && tab[i + 1] < Math.max(tab[j], tab[j + 1]))
if(tab[i] < Math.min(tab[j], tab[j + 1]) || tab[i] > Math.max(tab[j] , tab[j + 1]))
res = true;
if(tab[j + 1] > Math.min(tab[i], tab[i + 1]) && tab[j + 1] < Math.max(tab[i], tab[i + 1]))
if(tab[j] < Math.min(tab[i], tab[i + 1]) || tab[j] > Math.max(tab[i] , tab[i + 1]))
res = true;
}
}
System.out.println(res ? "yes" : "no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
int n;
cin >> n;
long long A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
if (n == 1) {
cout << "no";
return 0;
}
for (int i = 1; i < n; i++) {
long long nim1 = min(A[i], A[i - 1]), xam1 = max(A[i], A[i - 1]);
for (int j = 2; j < n; j++) {
long long nim2 = min(A[j], A[j - 1]), xam2 = max(A[j], A[j - 1]);
if (nim2 < nim1 && xam2 > nim1 && xam2 < xam1) {
cout << "yes";
return 0;
} else if (nim2 > nim1 && nim2 < xam1 && xam2 > xam1) {
cout << "yes";
return 0;
}
}
}
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | /*input
1
0
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static PrintWriter out;
static int MOD = 1000000007;
static FastReader scan;
/*-------- I/O using short named function ---------*/
public static String ns(){return scan.next();}
public static int ni(){return scan.nextInt();}
public static long nl(){return scan.nextLong();}
public static double nd(){return scan.nextDouble();}
public static String nln(){return scan.nextLine();}
public static void p(Object o){out.print(o);}
public static void ps(Object o){out.print(o + " ");}
public static void pn(Object o){out.println(o);}
/*-------- for output of an array ---------------------*/
static void iPA(int arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void lPA(long arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void sPA(String arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
static void dPA(double arr []){
StringBuilder output = new StringBuilder();
for(int i=0; i<arr.length; i++)output.append(arr[i] + " ");out.println(output);
}
/*-------------- for input in an array ---------------------*/
static void iIA(int arr[]){
for(int i=0; i<arr.length; i++)arr[i] = ni();
}
static void lIA(long arr[]){
for(int i=0; i<arr.length; i++)arr[i] = nl();
}
static void sIA(String arr[]){
for(int i=0; i<arr.length; i++)arr[i] = ns();
}
static void dIA(double arr[]){
for(int i=0; i<arr.length; i++)arr[i] = nd();
}
/*------------ for taking input faster ----------------*/
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
// Method to check if x is power of 2
static boolean isPowerOfTwo (int x) { return x!=0 && ((x&(x-1)) == 0);}
//Method to return lcm of two numbers
static int gcd(int a, int b){return a==0?b:gcd(b % a, a); }
// method to return LCM of two numbers
static int lcm(int a, int b){return (a / gcd(a, b)) * b;}
//Method to count digit of a number
static int countDigit(long n){return (int)Math.floor(Math.log10(n) + 1);}
//Method to find the max in an array
static int getMax(int arr[]){
int max = arr[0];
for(int i=0; i<arr.length; i++){
max = arr[i]>max?arr[i]:max;
}
return max;
}
//Method to find the min in an array
static int getMin(int arr[]){
int min = arr[0];
for(int i=0; i<arr.length; i++){
min = min>arr[i]?arr[i]:min;
}
return min;
}
//Method for sorting
static void ruffle_sort(int[] a) {
//shandom_ruffle
Random r=new Random();
int n=a.length;
for (int i=0; i<n; i++) {
int oi=r.nextInt(n);
int temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
//sort
Arrays.sort(a);
}
public static void main (String[] args) throws java.lang.Exception
{
OutputStream outputStream =System.out;
out =new PrintWriter(outputStream);
scan =new FastReader();
//for fast output sometimes
StringBuilder sb = new StringBuilder();
int n = ni();
int arr[] = new int[n];
iIA(arr);
TreeSet<Integer> set = new TreeSet<Integer>();
set.add(arr[0]);
if(n>1)
set.add(arr[1]);
//set.add(arr[2]);
set.add(Integer.MAX_VALUE);
set.add(Integer.MIN_VALUE);
int first=0, second=0;
if(n>1){
first = Math.min(arr[0], arr[1]);
second = Math.max(arr[0], arr[1]);
}
boolean check = false;
for(int i=3; i<n; i++){
int min = set.ceiling(arr[i-1]);
int max = set.ceiling(arr[i]);
//pn(min + " " + arr[i]);
//pn(first + " " + second);
if(min != Integer.MAX_VALUE){
if(min<arr[i] && (arr[i-1]>first || arr[i]<second)){
//pn(1);
check = true;
break;
}
}
if(max != Integer.MAX_VALUE){
if(max<arr[i-1] && (arr[i-1]<second || arr[i]>first)){
//pn(2);
check = true;
break;
}
}
set.add(arr[i-1]);
first = Math.min(first, arr[i-1]);
second = Math.max(second, arr[i-1]);
}
if(check)
pn("yes");
else
pn("no");
out.close();
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | length = int(input())
sequence = list(map(int, input().split()))
if length <= 3:
print('no')
else:
for i in range(length - 1):
w, x = sorted([sequence[i], sequence[i + 1]])
for j in range(length - 1):
y, z = sorted([sequence[j], sequence[j + 1]])
if w < y < x < z or y < w < z < x:
print('yes')
exit()
print('no') | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
l=list(map(int,input().split()))
for i in range(1,n) :
for j in range(i,0,-1) :
x,x1=max(l[i],l[i-1]),min(l[i],l[i-1])
y,y1=max(l[j],l[j-1]),min(l[j],l[j-1])
if x1>y1 and x1<y and x>y or x1<y1 and y1<x and x<y :
print('yes')
exit()
print('no')
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int main() {
int n;
cin >> n;
int x1, x2, x3, x4;
int array[n];
int i = 0, j = 0;
for (i = 0; i < n; i += 1) cin >> array[i];
bool ans = false;
for (i = 0; i < n; i += 1) {
if (i + 1 >= n) break;
x1 = array[i];
x2 = array[i + 1];
if (x1 > x2) swap(&x1, &x2);
for (j = 0; j < n; j += 1) {
if (j + 1 >= n) break;
x3 = array[j];
x4 = array[j + 1];
if (x3 > x4) swap(&x3, &x4);
if (x1 < x3 and x3 < x2 and x2 < x4) {
ans = true;
break;
} else if (x3 < x1 and x1 < x4 and x4 < x2) {
ans = true;
break;
}
}
}
if (ans)
cout << "yes" << endl;
else
cout << "no" << endl;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StreamCorruptedException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution
{
public static void main(String[] args) {
new Solution().solve();
}
PrintWriter out;
public void solve()
{
out=new PrintWriter(System.out);
int n=in.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=in.nextInt();
}
if(n==1 ||n==2 || n==3)
{
System.out.println("no");
System.exit(0);
}
for(int i=0;i<n-1;i++)
{
int lower;
int higher;
if(arr[i]<arr[i+1])
{
lower=arr[i];
higher=arr[i+1];
}
else
{
lower=arr[i+1];
higher=arr[i];
}
for(int j=0;j<n-1;j++)
{
int lower1;
int higher1;
if(arr[j]<arr[j+1])
{
lower1=arr[j];
higher1=arr[j+1];
}
else
{
lower1=arr[j+1];
higher1=arr[j];
}
if(lower1<lower && higher1>lower && higher1<higher)
{
System.out.println("yes");
System.exit(0);
}
else if(lower1>lower && lower1<higher && higher1>higher)
{
System.out.println("yes");
System.exit(0);
}
}
}
System.out.println("no");
out.close();
}
FasterScanner in=new FasterScanner();
public class FasterScanner {
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = System.in.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String nextString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import sys
n = int(input())
inp = input().split()
x = [int(p) for p in inp]
for i in range(0,n-2):
for j in range(i+1,n-1):
# (i,i+1) vs. (j,j+1)
al = min(x[i],x[i+1])
ar = max(x[i],x[i+1])
#print(i,j,al,ar,x[j],x[j+1])
ins1 = al<x[j] and x[j]<ar and (x[j+1]<al or x[j+1]>ar)
ins2 = al<x[j+1] and x[j+1]<ar and (x[j]<al or x[j]>ar)
if ins1 or ins2:
print("yes")
sys.exit()
"""
x = []
for i in range(0,n):
x.append([int(inp[i]),i+1])
x.sort()
#print(x)
#for i in range(0,n):
# print(x[i][1])
#
be = 0
en = n-1
cur = 1
while be != en:
if x[be][1]==cur:
cur += 1
be += 1
elif x[en][1]==cur:
cur += 1
en -= 1
else:
print("yes")
sys.exit()
"""
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int betw(int z, int x, int y) { return z < max(x, y) && z > min(x, y); }
int main() {
int a[1010], n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
bool flag = false;
for (int i = 1; i < n; i++)
for (int j = 1; j < n; j++) {
if (a[j] == a[i] || a[j] == a[i + 1] || a[j + 1] == a[i] ||
a[j + 1] == a[i + 1])
continue;
int f = betw(a[j], a[i], a[i + 1]) ^ betw(a[j + 1], a[i], a[i + 1]);
if (f) flag = true;
}
if (flag)
cout << "yes" << endl;
else
cout << "no" << endl;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
l = list(map(int, input().split()))
result = True
for i in range(n-2):
li, ri = min(l[i], l[i+1]), max(l[i], l[i+1])
for j in range(i+2, n-1):
lj, rj = min(l[j], l[j+1]), max(l[j], l[j+1])
if (li < lj < ri and not(li < rj < ri)) or (li < rj < ri and not(li < lj < ri)):
result = False
break
if (lj < ri < rj and not(lj < li < rj)) or (lj < li < rj and not(lj < ri < rj)):
result = False
break
if not result:
break
if result:
print("no")
else:
print("yes") | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
/**
* @author Assassin
*/
public class A {
private BufferedReader reader;
private PrintWriter out;
private StringTokenizer tokenizer;
//private final String filename = "filename";
private void init(InputStream input, OutputStream output) throws IOException {
reader = new BufferedReader(new InputStreamReader(input));
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output)));
//reader = new BufferedReader(new FileReader(filename + ".in"));
//out = new PrintWriter(new FileWriter(filename + ".out"));
tokenizer = new StringTokenizer("");
}
private String nextLine() throws IOException {
return reader.readLine();
}
private String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(next());
}
private long nextLong() throws IOException {
return Long.parseLong(next());
}
private double nextDouble() throws IOException {
return Double.parseDouble(next());
}
private void run() throws IOException {
init(System.in, System.out);
//long startTime = System.currentTimeMillis();
int n = nextInt();
if (n == 1) {
out.println("no");
} else {
int[] x = new int[n];
for (int i = 0; i < n; i++) {
x[i] = nextInt();
}
boolean yes = false;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
int l1 = Math.min(x[i], x[i + 1]);
int r1 = Math.max(x[i], x[i + 1]);
int l2 = Math.min(x[j], x[j + 1]);
int r2 = Math.max(x[j], x[j + 1]);
if ((l1 < l2 && l2 < r1 && r1 < r2) || (l2 < l1 && l1 < r2 && r2 < r1)) {
yes = true;
break;
}
if (yes) {
break;
}
}
}
if (yes) {
out.println("yes");
} else {
out.println("no");
}
}
//long runTime = System.currentTimeMillis() - startTime;
//out.write(runTime + "\n");
out.close();
System.exit(0);
}
public static void main(String[] args) throws IOException {
new A().run();
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n <= 2) {
cout << "no";
return 0;
}
vector<pair<int, int>> z;
int a, b, c;
cin >> a;
cin >> b;
for (int i = 0; i < n - 2; i++) {
cin >> c;
for (int j = 0; j < z.size(); j++) {
if (c >= z[j].first && c <= z[j].second) {
cout << "yes";
return 0;
}
}
if ((c < a && c > b) || (c > a && c < b)) {
pair<int, int> tmp;
tmp.first = -1000001;
;
tmp.second = min(a, b);
z.push_back(tmp);
tmp.first = max(a, b);
tmp.second = 1000001;
z.push_back(tmp);
a = b;
b = c;
continue;
}
if ((c < a && c < b) || (c > a && c > b)) {
pair<int, int> tmp;
tmp.first = min(a, b);
tmp.second = max(a, b);
z.push_back(tmp);
a = b;
b = c;
continue;
}
cout << "yes";
return 0;
}
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 100;
int a[maxN];
bool intersect(int a2, int a1, int b2, int b1) {
if (b1 > a1 && b1 < a2) {
if (b2 > a2 || b2 < a1)
return true;
else
return false;
} else if (b2 > a1 && b2 < a2) {
if (b1 < a1 || b1 > a2)
return true;
else
return false;
}
return false;
}
int main() {
bool flag = false;
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++)
for (int j = 1; j < n; j++)
if (fabs(j - i) >= 2)
if (intersect(max(a[i], a[i + 1]), min(a[i + 1], a[i]),
max(a[j], a[j + 1]), min(a[j + 1], a[j])))
flag = true;
if (flag)
cout << "yes";
else
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n=in.nextInt();
int[] a=new int[n];
for (int i = 0; i < n; i++) {
a[i]=in.nextInt();
}
boolean ok=true;
for (int i=1;i<n-1;i++){
for (int j=0;j<i;j++){
if ((inside(a[i],a[j],a[j+1])&&outside(a[i+1],a[j],a[j+1]))||(inside(a[i+1],a[j],a[j+1])&&outside(a[i],a[j],a[j+1])))
{
ok=false;
// System.err.println(i+"+"+j);
}
}
}
if (ok) out.print("no");
else out.print("yes");
}
private boolean inside(int a,int b,int c){
return (long)(a-b)*(a-c)<0;
}
private boolean outside(int a,int b,int c){
return (long)(a-b)*(a-c)>0;
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
l=list(map(int,input().split()))
if n<4:
print("no")
else:
prev=l[1]
ans="no"
for i in range(2,n):
for j in range(1,n):
if min(l[j],l[j-1])<min(prev,l[i])<max(l[j],l[j-1]) and max(l[i],prev)>max(l[j],l[j-1]):
ans="yes"
break
if min(l[j],l[j-1])<max(prev,l[i])<max(l[j],l[j-1]) and min(l[i],prev)<min(l[j],l[j-1]):
ans="yes"
break
if ans=="yes":
break
prev=l[i]
print(ans) | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5;
long long n;
long long x[N];
map<long long, long long> last;
bool intersect(long long a, long long b, long long c, long long d) {
vector<pair<long long, long long> > v;
v.push_back({a, 1});
v.push_back({b, 1});
v.push_back({c, 2});
v.push_back({d, 2});
map<long long, long long> m;
m[a]++;
m[b]++;
m[c]++;
m[d]++;
if (m.size() < 4) return 0;
sort(v.begin(), v.end());
if (v[0].second == v[2].second) return 1;
return 0;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> x[i];
for (long long i = 1; i <= n - 1; i++) {
for (long long j = 1; j <= n - 1; j++) {
if (i == j) continue;
if (intersect(x[i], x[i + 1], x[j], x[j + 1])) {
cout << "yes";
return 0;
}
}
}
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int between(int a, int b, int c) { return a > b and a < c; }
int main() {
int n, X[1001];
vector<pair<int, int> > v;
cin >> n;
for (int i = 0; i < n; i++) cin >> X[i];
if (n == 1)
cout << "no\n";
else {
int last = X[0];
for (int i = 1; i < n; i++) {
if (v.size() > 1) {
for (int j = 0; j < v.size() - 1; j++) {
if ((between(last, v[j].first, v[j].second) and
!between(X[i], v[j].first, v[j].second)) ||
(!between(last, v[j].first, v[j].second) and
between(X[i], v[j].first, v[j].second))) {
cout << "yes\n";
goto salir;
}
}
}
if (X[i] < last)
v.push_back(make_pair(X[i], last));
else if (X[i] > last)
v.push_back(make_pair(last, X[i]));
last = X[i];
}
cout << "no\n";
salir:;
}
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
vector<int> points;
int main() {
int n, e;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> e;
points.push_back(e);
}
for (int i = 1; i < n; ++i) {
if (points[i - 1] < points[i])
v.push_back(pair<int, int>(points[i - 1], points[i]));
else
v.push_back(pair<int, int>(points[i], points[i - 1]));
}
bool f = 0;
for (int i = 0; i < v.size(); ++i) {
for (int j = i + 1; j < v.size(); ++j) {
if (v[i].first == v[j].first || v[i].second == v[j].second) continue;
if (v[i].first < v[j].first && v[j].first < v[i].second &&
v[i].second < v[j].second)
f = 1;
if (v[j].first < v[i].first && v[i].first < v[j].second &&
v[j].second < v[i].second)
f = 1;
}
}
if (f)
cout << "yes";
else
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = raw_input()
n = int(n)
s = raw_input()
ss = s.split(' ')
for i in xrange(len(ss)):
ss[i] = int(ss[i])
if len(ss) <= 2:
print 'no'
else :
lst = []
#print ss
for i in xrange(len(ss) - 1):
#print i
if ss[i] < ss[i + 1]:
lst.append((ss[i], ss[i + 1],))
else :
lst.append((ss[i+1], ss[i],))
ret = False
for i in xrange(len(lst)):
for j in xrange(i + 1, len(lst)):
if not ((lst[i][1] <= lst[j][0] or lst[j][1] <= lst[i][0]) or (lst[i][0] >= lst[j][0] and lst[i][1] <= lst[j][1]) \
or (lst[j][0] >= lst[i][0] and lst[j][1] <= lst[i][1])):
ret = True
if ret:
print 'yes'
else :
print 'no'
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | //package c208;
import java.util.Scanner;
public class q1
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
boolean ans=false;
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
}
for(int i=0;i<n-1;i++)
{
int x3=Math.min(a[i],a[i+1]);
int x4=Math.max(a[i],a[i+1]);
for(int j=0;j<i;j++)
{
int x1=Math.min(a[j],a[j+1]);
int x2=Math.max(a[j],a[j+1]);
//System.out.println(i+" "+j+" "+x1+" "+x2+" "+x3+" "+x4);
if(x1<x3&&x3<x2&&x2<x4)
{//System.out.println(4);
ans=true;
}
if(x3<x1 && x1<x4 && x4<x2)
{//System.out.println(4);
ans=true;
}
}
}
if(ans)
System.out.println("yes");
else
System.out.println("no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
pre = 999999
segs = []
for x in map(int, input().split()):
if pre != 999999:
segs.append((min(pre, x), max(pre, x)))
pre = x
segs.sort()
intersect = False
for i in range(0, len(segs)):
for j in range(i, len(segs)):
if segs[i][0] < segs[j][0] < segs[i][1] < segs[j][1]:
intersect = True
break
print('yes' if intersect else 'no')
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.*;import java.io.*;import java.math.*;
public class Dima
{
public static void process()throws IOException
{
int n=ni();
int[]A=nai(n);
if(n<4)
{
pn("no");
return;
}
for(int i=3;i<n;i++)
{
for(int j=0;j<i-1;j++)
{
int x1=Math.min(A[j],A[j+1]);
int y1=Math.max(A[j],A[j+1]);
int x2=Math.min(A[i],A[i-1]);
int y2=Math.max(A[i],A[i-1]);
if(check(x1,y1,x2,y2))
{
pn("yes");
return;
}
}
}
pn("no");
}
static boolean check(int x1,int y1,int x2,int y2)
{
if(y2>x1 && y2<y1 && x2<x1)
return true;
if(x2>x1 && x2<y1 && y2>y1)
return true;
return false;
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
int t=1;
// t=ni();
while(t-->0) {process();}
out.flush();out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, a1, a2, b1, b2;
int a[1005];
bool check(int i, int j) {
a1 = a[i];
b1 = a[i + 1];
a2 = a[j];
b2 = a[j + 1];
if (a1 > b1) swap(a1, b1);
if (a2 > b2) swap(a2, b2);
if ((a1 > a2 && a1 < b2 && b1 > b2) || (a1 < a2 && b1 > a2 && b1 < b2))
return 1;
else
return 0;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n - 1; j++)
if (check(i, j)) {
printf("yes\n");
exit(0);
}
printf("no\n");
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | def Intersect(aa,bb,xx,yy):
a=min(aa,bb)
b=max(aa,bb)
x=min(xx,yy)
y=max(xx,yy)
if(a>=x and b<=y):
return False
if(x>=a and y<=b):
return False
if(b<=x):
return False
if(y<=a):
return False
return True
N=int(input())
case=False
L=list(map(int,input().split()))
for i in range(N-1):
for j in range(i+1,N-1):
if(Intersect(L[i],L[i+1],L[j],L[j+1])):
case=True
if(case):
print("yes")
else:
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
arr = list(map(int, input().split()))
flag = 0
for i in range(n-1):
for j in range(i+1,n-1):
a,b = min(arr[i],arr[i+1]),max(arr[i],arr[i+1])
c,d = min(arr[j],arr[j+1]),max(arr[j],arr[j+1])
if a<c<b<d or c<a<d<b:
flag=1
break
if flag==1:
break
if flag==0:
print("no")
else:
print("yes")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args) {
if (args.length > 0 && args[0].toLowerCase().equals("local")) {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new File("output.txt")));
} catch (IOException exc) {
}
}
Task task = new Task();
task.solve();
}
public static class Task {
static final long MOD = (long) 1e9 + 7;
static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public void solve() {
try {
Scan sc = new Scan();
int n = (int) sc.scanLong();
int[] arr = new int[n];
int[] next = new int[n];
for (int i = 0; i < n; ++i) {
int curr = (int) sc.scanLong();
arr[i] = curr;
if (i > 0)
next[i - 1] = curr;
}
next[n - 1] = arr[n - 1];
for (int i = 0; i < n; ++i) {
int curr1 = arr[i];
int next1 = next[i];
if (curr1 > next1) {
int temp = curr1;
curr1 = next1;
next1 = temp;
}
for (int j = i + 1; j < n; ++j) {
int curr2 = arr[j];
int next2 = next[j];
if (curr2 > next2) {
int temp = curr2;
curr2 = next2;
next2 = temp;
}
if (curr2 > curr1 && curr2 < next1 && (next2 > next1 || next2 < curr1)) {
out.println("yes");
return;
}
if (next2 > curr1 && next2 < next1 && (curr2 < curr1 || curr2 > next1)) {
out.println("yes");
return;
}
}
}
out.println("no");
} finally {
out.close();
}
}
private void debug(Object... x) {
StringBuilder sb = new StringBuilder();
for (Object o : x)
sb.append(String.valueOf(o)).append(" ");
out.println(sb);
}
}
public static class Scan {
private byte[] buf = new byte[1024];
private int index;
private InputStream in;
private int total;
public Scan() {
in = System.in;
}
public int scan() {
if (total < 0)
throw new InputMismatchException();
if (index >= total) {
index = 0;
try {
total = in.read(buf);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (total <= 0)
return -1;
}
return buf[index++];
}
public long scanLong() {
long integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
return neg * integer;
}
public double scanDouble() {
double doub = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n) && n != '.') {
if (n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
if (n == '.') {
n = scan();
double temp = 1;
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = scan();
} else
throw new InputMismatchException();
}
}
return doub * neg;
}
public String scanString() {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n))
n = scan();
while (!isWhiteSpace(n)) {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
public char scanChar() {
int n = scan();
while (isWhiteSpace(n))
n = scan();
return (char) n;
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = input()
a = map(int,raw_input().split())
ans = "no"
for i in range(n-1):
for j in range(n-1):
x1,x2 = sorted([a[i], a[i+1]])
x3,x4 = sorted([a[j], a[j+1]])
if x1<x3<x2 and x3<x2<x4:
ans = "yes"
print ans | PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import sys
import fractions
a = sys.stdin.readline()
n = int(a)
a = sys.stdin.readline()
a = a.strip().split()
a = [int(i) for i in a]
def isInter(c1, c2):
if c1[0] > c2[0] and c1[0] < c2[1] and c1[1] > c2[1]:
return True
if c1[1] > c2[0] and c1[1] < c2[1] and c1[0] < c2[0]:
return True
return False
if len(a) <= 2:
print "no"
else:
ret = "no"
circs = [ [min(a[0],a[1]), max(a[0],a[1])] ]
for i in range(2, n):
if ret == "yes":
break
tmpcirc = [min(a[i],a[i-1]), max(a[i],a[i-1])]
for c in circs:
if isInter(c, tmpcirc):
ret = "yes"
break
if ret == "no":
circs.append(tmpcirc)
print ret
| PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | # your code goes here
n = input()
arr = map(int, raw_input().split())
i = 0
t = True
while i<n-1:
j = 0
while j<n-1:
a = arr[i]
b = arr[i+1]
c = arr[j]
d = arr[j+1]
if a>b:
a,b = b,a
if c>d:
c,d = d,c
if a<c<b<d:
t = False
j+=1
i+=1
if t:
print 'no'
else:
print 'yes' | PYTHON |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.*;
import java.util.*;
public class Test {
static FastScanner sc;
static boolean[] visited;
static int four = 0, seven = 0;
public static void main(String args[]) {
sc = new FastScanner(System.in);
solve();
}
public static void solve() {
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int a = 0, b = 0, c = 0, d = 0;
for (int i = 1; i < arr.length; i++) {
a = Math.min(arr[i - 1], arr[i]);
b = Math.max(arr[i - 1], arr[i]);
for (int j = i + 1; j < arr.length; j++) {
c = Math.min(arr[j - 1], arr[j]);
d = Math.max(arr[j - 1], arr[j]);
// System.err.println(a + " " + b + " - " + c + " " + d);
if ((b > c && d > b && c > a) || (a > c && d > a && b > d)) {
System.out.println("yes");
return;
}
}
}
System.out.println("no");
}
}
class FastScanner {
BufferedReader reader;
StringTokenizer tokenizer;
FastScanner(InputStream inputStream) {
reader = new BufferedReader(new InputStreamReader(inputStream));
}
String nextToken() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 |
import java.util.LinkedList;
import java.util.Scanner;
public class A_Line {
static class Line {
int a, b;
Line(int a, int b) {
this.a = a;
this.b = b;
}
public String toString() {
return "[" + a + "," + b + "]";
}
boolean intersect(Line l) {
int x0, y0, x1, y1;
x0 = a < b ? a : b;
y0 = a < b ? b : a;
x1 = l.a < l.b ? l.a : l.b;
y1 = l.a < l.b ? l.b : l.a;
return ((x0 > x1 && x0 < y1) && (y0 < x1 || y0 > y1)) || ((y0 > x1 && y0 < y1) && (x0 < x1 || x0 > y1));
}
}
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
LinkedList<Line> lx = new LinkedList<>();
if (n <= 3) {
System.out.println("no");
} else {
int x;
boolean yes = false;
lx.add(new Line(input.nextInt(), input.nextInt()));
int i;
for (i = 2; i < n && !yes; i++) {
x = input.nextInt();
Line l = new Line(lx.getLast().b, x);
for (Line ln : lx) {
if (l.intersect(ln)) {
yes = true;
break;
}
}
lx.add(l);
}
System.out.println(!yes ? "no" : "yes");
}
input.close();
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
string res = "no";
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (i != j) {
int x1 = min(a[i], a[i + 1]);
int x2 = max(a[i], a[i + 1]);
int x3 = min(a[j], a[j + 1]);
int x4 = max(a[j], a[j + 1]);
if (x1 < x3 && x3 < x2 && x2 < x4) {
res = "yes";
break;
} else if (x3 < x1 && x1 < x4 && x4 < x2) {
res = "yes";
break;
}
}
}
if (res == "yes") break;
}
cout << res;
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
long *Coordinates;
Coordinates = (long *)malloc((n + 1) * sizeof(int));
int i;
for (i = 0; i < n; i++) {
scanf("%ld", &Coordinates[i]);
}
int num = n;
long *x, *y;
x = (long *)malloc(num * sizeof(int));
y = (long *)malloc(num * sizeof(int));
int temp;
for (i = 0; i < n - 1; i++) {
x[i] = Coordinates[i];
y[i] = Coordinates[i + 1];
}
for (i = 1; i < n - 1; ++i) {
temp = i;
while (temp >= 0) {
if ((Coordinates[i] > x[temp] && Coordinates[i] < y[temp]) ||
(Coordinates[i] < x[temp] && Coordinates[i] > y[temp])) {
if (x[temp] < y[temp]) {
if (Coordinates[i + 1] < x[temp] || Coordinates[i + 1] > y[temp]) {
printf("yes");
return 0;
}
} else {
if (Coordinates[i + 1] > x[temp] || Coordinates[i + 1] < y[temp]) {
printf("yes");
return 0;
}
}
} else if ((Coordinates[i + 1] > x[temp] &&
Coordinates[i + 1] < y[temp]) ||
(Coordinates[i + 1] < x[temp] &&
Coordinates[i + 1] > y[temp])) {
if (x[temp] < y[temp]) {
if (Coordinates[i] < x[temp] || Coordinates[i] > y[temp]) {
printf("yes");
return 0;
}
} else {
if (Coordinates[i] > x[temp] || Coordinates[i] < y[temp]) {
printf("yes");
return 0;
}
}
}
--temp;
}
}
printf("no");
free(Coordinates);
free(x);
free(y);
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class ContinuousLine {
public static class Intervalo{
public int min;
public int max;
public Intervalo (int num1, int num2){
min = Integer.min(num1, num2);
max = Integer.max(num1, num2);
}
public boolean inside(int num){
return (num>min && num < max);
}
public boolean greater(int num){
return (num>max);
}
public boolean lower(int num){
return (num<min);
}
}
public static boolean isBetween(int num1, int num2, int cand){
int min = Integer.min(num1, num2);
int max = Integer.max(num1, num2);
if (cand>min && cand < max)
return true;
return false;
}
private static boolean inside(ArrayList<Intervalo> excluded, int num) {
for(int i = 0; i<excluded.size(); i++)
if (excluded.get(i).inside(num))
return true;
return false;
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String data = in.readLine();
@SuppressWarnings("unused")
int n = Integer.parseInt(data);
String[] numbers = in.readLine().split(" ");
Intervalo outer = new Intervalo(Integer.MIN_VALUE, Integer.MAX_VALUE);
ArrayList<Intervalo> excluded = new ArrayList<Intervalo>();
if (n>1){
int ini = Integer.parseInt(numbers[0]);
int end = Integer.parseInt(numbers[1]);
for(int i = 2; i<numbers.length; i++){
int num = Integer.parseInt(numbers[i]);
if (!outer.inside(num) || inside(excluded, num)){
System.out.println("yes");
return;
}
if (isBetween(ini, end, num)){
outer = new Intervalo(ini, end);
excluded.clear();
}
else if (isBetween(Integer.max(ini, end), outer.max, num)){
excluded.add(new Intervalo(ini, end));
}
else if (isBetween(Integer.min(ini, end), outer.min, num)){
excluded.add(new Intervalo(ini, end));
}
ini = end;
end = num;
}
System.out.println("no");
}
else
System.out.println("no");
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int input[1010];
struct node {
int start;
int end;
node(){};
node(int _start, int _end) {
start = _start;
end = _end;
}
} nodes[1000];
int main() {
int n;
while (cin >> n) {
bool flag = false;
int xi = 0;
for (int i = 0; i < n; i++) {
cin >> input[i];
}
for (int i = 0; i < n - 1; i++) {
int start = input[i];
int end = input[i + 1];
if (start > end) swap(start, end);
nodes[i] = node(start, end);
}
for (int i = 0; i < n - 1; i++) {
int istart = nodes[i].start;
int iend = nodes[i].end;
for (int j = 0; j < i; j++) {
int jstart = nodes[j].start;
int jend = nodes[j].end;
if (jstart < istart) {
if (jend > istart && iend > jend) flag = true;
} else if (jstart > istart) {
if (iend > jstart && jend > iend) flag = true;
}
}
if (flag == true) break;
}
if (flag)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for (int j = 0; j < n; ++j) arr[j] = s.nextInt();
String out = "no";
for (int k = 1; k < n; ++k) {
for (int l = k + 1; l < n; ++l) {
int a1 = arr[k-1]; int b1 = arr[k]; if (a1 > b1) { int t = a1; a1 = b1; b1 = t; }
int a2 = arr[l-1]; int b2 = arr[l]; if (a2 > b2) { int t = a2; a2 = b2; b2 = t; }
if ((a1 == a2) || (b1 == b2) || (a2 == b1) || (a1 == b2)) continue;
if (b1 < a2 || b2 < a1) continue;
if (a2 > a1 && b2 < b1) continue;
if (a1 > a2 && b1 < b2) continue;
else { out = "yes"; break; }
}
if (out.equals("yes")) break;
}
System.out.println(out);
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import sys
sys.setrecursionlimit(100000)
n = int(sys.stdin.readline().strip())
arr = [int(x) for x in sys.stdin.readline().strip().split()]
pair = [(min(arr[x],arr[x+1]),max(arr[x],arr[x+1]))
for x in range(0,n-1)]
flag = False
for i in range(0,n-2):
p = pair[i]
for j in range(i+1,n-1):
k = pair[j]
if p[0]<k[0]<p[1]<k[1] or k[0]<p[0]<k[1]<p[1]:
flag = True
break
if flag:
print("yes")
else:
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] array= new int[N];
for(int a=0;a<N;a++)array[a]=sc.nextInt();
boolean OK = true;
for(int a=0;a<N-1;a++){
int L1 = Math.min(array[a],array[a+1]);
int R1 = Math.max(array[a],array[a+1]);
for(int b=a+2;b<N-1;b++){
int L2 = Math.min(array[b],array[b+1]);
int R2 = Math.max(array[b],array[b+1]);
if(L1<L2&&L2<R1&&R1<R2)OK=false;
if(L2<L1&&L1<R2&&R2<R1)OK=false;
}
}
System.out.println(OK?"no":"yes");
}
} | JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ma = max(a[0], a[1]);
ma = max(a[2], ma);
int mi = min(a[0], a[1]);
mi = min(a[2], mi);
for (int i = 3; i < n; i++) {
ma = max(a[i], ma);
mi = min(a[i], mi);
if ((a[i] == ma && a[i - 1] == mi) || (a[i] == mi && a[i - 1] == ma)) {
continue;
}
for (int j = 0; j < i; j++) {
if (a[i] > a[i - 1]) {
if (a[j] > a[i - 1] && a[j] < a[i]) {
cout << "yes";
return 0;
}
} else {
if (a[j] < a[i - 1] && a[j] > a[i]) {
cout << "yes";
return 0;
}
}
}
}
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
int num[1005];
using namespace std;
int judge(int x1, int x2, int x3, int x4) {
if (x1 > x2) swap(x1, x2);
if (x3 > x4) swap(x3, x4);
if (x1 < x3 && x3 < x2 && x2 < x4) return (1);
if (x3 < x1 && x1 < x4 && x4 < x2) return (1);
return (0);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
}
int i, err = 0;
for (i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (judge(num[i], num[i + 1], num[j], num[j + 1])) {
printf("yes");
err = 1;
}
if (err == 1) break;
}
if (err == 1) break;
}
if (i == n - 1) printf("no");
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
l1=list(map(int,input().split()))
pairs=[]
for i in range(n-1):
pairs.append((min(l1[i],l1[i+1]),max(l1[i],l1[i+1])))
flag=0
for i in range(n-1):
for j in range(i+1,n-1):
if pairs[i][0]>pairs[j][0] and pairs[i][0]<pairs[j][1] and pairs[i][1]>pairs[j][1]:
flag=1
break
elif pairs[i][0]<pairs[j][0] and pairs[i][1]>pairs[j][0] and pairs[i][1]<pairs[j][1]:
flag=1
break
if flag==1:
break
if flag==1:
print("yes")
else :
print("no")
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 |
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""
n=int(input())
a=list(map(int,input().split()))
p=[]
for i in range(n-1):
p.append([min(a[i],a[i+1]),max(a[i],a[i+1])])
for i in p:
for j in p:
if i[0]<j[0]<i[1]<j[1] or j[0]<i[0]<j[1]<i[1]:
print("yes")
exit()
print("no") | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int num[1211];
inline bool cross(int a, int b) {
int x0 = num[a];
int x1 = num[a + 1];
int y0 = num[b];
int y1 = num[b + 1];
if (x0 > x1) swap(x0, x1);
if (y0 > y1) swap(y0, y1);
if (x0 < y0 && x1 > y0 && x1 < y1) return true;
if (x0 > y0 && x0 < y1 && x1 > y1) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> num[i];
bool flag = false;
for (int i = 0; i < n - 1; i++)
for (int j = i + 2; j < n - 1; j++)
if (cross(i, j)) flag = true;
if (flag)
cout << "yes\n";
else
cout << "no\n";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input());a=list(map(int,input().split()));b,c,ok=[],[],1
for i in range(n-1):
b.append(min(a[i],a[i+1]));c.append(max(a[i],a[i+1]));
for i in range(n-1):
for j in range(n-1):
if(i==j):continue
if(b[i]<b[j] and c[i]>b[j] and c[j]>c[i]):ok=0
if(ok):print('no')
else:print('yes') | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int xs[1000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
cin >> xs[i];
}
bool ok = 1;
for (int i = 0; i < n - 1; ++i) {
int st = min(xs[i], xs[i + 1]);
int ed = max(xs[i], xs[i + 1]);
for (int j = 0; j < n - 1; ++j) {
if (i != j) {
int st1 = min(xs[j], xs[j + 1]);
int ed1 = max(xs[j], xs[j + 1]);
if ((st1 > st && st1 < ed && ed1 > ed) ||
(ed1 > st && ed1 < ed && st1 < st)) {
ok = 0;
break;
}
}
}
if (!ok) break;
}
if (ok)
cout << "no" << endl;
else
cout << "yes" << endl;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, p[1005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", p + i);
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n - 1; j++) {
int a = min(p[i], p[i + 1]);
int b = max(p[i], p[i + 1]);
int c = min(p[j], p[j + 1]);
int d = max(p[j], p[j + 1]);
if ((c > a && c < b && d > b) || (d > a && d < b && c < a))
return puts("yes"), 0;
}
puts("no");
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n=int(input())
arr=list(map(int , input().split()))
l=[]
for i in range(1,n):
m1=min(arr[i],arr[i-1])
m2=max(arr[i],arr[i-1])
l.append((m1,m2))
flag=0
for i in range(1,n-1):
lb=l[i][0]
ub=l[i][1]
for j in range(0,i):
if(lb>=l[j][0] and ub<=l[j][1]):
continue
if(ub<=l[j][0] or lb>=l[j][1]):
continue
if(lb<=l[j][0] and ub>=l[j][1]):
continue
else:
print("yes")
exit()
print("no") | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n= int(input())
l= list(map(int, input().split()))
ans='no'
for i in range(0, n-1):
for j in range(0, n-1):
x1,x2= sorted([l[i], l[i+1]])
x3,x4= sorted([l[j], l[j+1]])
if x1<x3<x2 and x3<x2<x4:
ans='yes'
print(ans) | PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int t[1003];
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 1; i < n - 1; i++) {
for (int j = i; j < n - 1; j++) {
int x = min(t[j], t[j + 1]), y = max(t[j], t[j + 1]);
int a = min(t[i - 1], t[i]), b = max(t[i - 1], t[i]);
if ((x < b and a < x and b < y) or (x < a and a < y and y < b)) {
cout << "yes";
return 0;
}
}
}
cout << "no";
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1 || n == 2 || n == 3) {
cout << "no";
return 0;
}
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++)
if (max(a[i], a[i + 1]) < max(a[j], a[j + 1]) &&
min(a[i], a[i + 1]) < min(a[j], a[j + 1]) &&
max(a[i], a[i + 1]) > min(a[j], a[j + 1])) {
cout << "yes";
return 0;
}
}
cout << "no";
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
x = [int(i) for i in input().split()]
if (n < 3):
print ('no')
else:
ans = 'no'
for i in range(3, n):
prev = x[i - 1]
num = x[i]
for j in range(i - 2):
num1 = min(x[j], x[j + 1])
num2 = max(x[j], x[j + 1])
if (prev < num1 or prev > num2) and (num > num1 and num < num2):
ans = 'yes'
break
elif ((num < num1 or num > num2) and (prev > num1 and prev < num2)):
ans = 'yes'
break
print (ans)
| PYTHON3 |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class Solution_A implements Runnable {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tokenizer;
public static void main(String[] args) {
new Thread(null, new Solution_A(), "", 256 * (1L << 20)).start();
}
public void run() {
try {
long t1 = System.currentTimeMillis();
if (System.getProperty("ONLINE_JUDGE") != null) {
out = new PrintWriter(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
} else {
out = new PrintWriter("output.txt");
in = new BufferedReader(new FileReader("input.txt"));
}
Locale.setDefault(Locale.US);
solve();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Throwable t) {
t.printStackTrace(System.err);
System.exit(-1);
} finally {
try {
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
}
// solution
void solve() throws IOException {
String line = in.readLine();
int pointCount;
if (line != null) {
pointCount = Integer.parseInt(line);
long[] points = new long[pointCount];
tokenizer = new StringTokenizer(in.readLine(), " ");
int i = 0;
while (tokenizer.hasMoreTokens()) {
points[i] = Long.parseLong(tokenizer.nextToken());
i++;
}
for (i = 0; i < pointCount-1; i++) {
Long firstMax = Math.max(points[i], points[i+1]);
Long firstMin = Math.min(points[i], points[i+1]);
for (int j = i+1; j < pointCount - 1; j++) {
Long secondMax = Math.max(points[j], points[j+1]);
Long secondMin = Math.min(points[j], points[j+1]);
if (secondMin > firstMin && secondMin < firstMax && secondMax > firstMax){
out.print("yes");
return;
}
if (secondMin < firstMin && firstMin < secondMax && secondMax < firstMax){
out.print("yes");
return;
}
}
}
out.print("no");
} else {
out.print("no");
}
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int x[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i];
int flag = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n - 1; j++) {
int t1 = min(x[i], x[i + 1]);
int t2 = max(x[i], x[i + 1]);
if (t1 >= x[j] && t1 >= x[j + 1]) continue;
if (t2 <= x[j] && t2 <= x[j + 1]) continue;
if (t1 >= min(x[j], x[j + 1]) && t2 <= max(x[j], x[j + 1])) continue;
if (t1 <= min(x[j], x[j + 1]) && t2 >= max(x[j], x[j + 1])) continue;
flag = 1;
}
if (flag)
puts("yes");
else
puts("no");
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int max_n = 1e3;
int n;
int cor[max_n + 1];
void input() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> cor[i];
}
}
bool check(int l1, int r1, int l2, int r2) {
if (l1 == l2 && r1 == r2) return true;
if (l2 > l1 && l2 < r1 && r2 > r1) return true;
if (l2 < l1 && r2 > l1 && r2 < r1) return true;
return false;
}
void output() {
bool flag = false;
for (int i = 0; i < n - 1; i++) {
int cur_l = min(cor[i], cor[i + 1]), cur_r = max(cor[i + 1], cor[i]);
for (int j = 0; j < n - 1; j++) {
if (j == i) continue;
if (check(cur_l, cur_r, min(cor[j], cor[j + 1]),
max(cor[j], cor[j + 1]))) {
flag = true;
goto ans;
}
}
}
ans:;
if (flag)
cout << "yes\n";
else
cout << "no\n";
}
int main() {
input();
output();
return 0;
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // <= 10^3
int[] val = new int[n];
for (int i = 0; i < n; i++) val[i] = sc.nextInt();
String result = "no";
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n - 1; j++) {
int a = val[i];
int b = val[i + 1];
int c = val[j];
int d = val[j + 1];
if (a < b) {
int temp = b;
b = a;
a = temp;
}
if (c < d) {
int temp = d;
d = c;
c = temp;
} // so that b >= d, a >= c.
if (b < d && d < a && a < c) result = "yes";
if (d < b && b < c && c < a) result = "yes";
}
}
System.out.println(result);
}
}
| JAVA |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> mpp;
vector<vector<pair<int, int> > > AdjList;
vector<int> visited;
priority_queue<pair<int, int> > pq;
int main() {
ios_base::sync_with_stdio(false);
int n;
int temp;
cin >> n;
int a[10000];
for (int i = 0; i < n; i++) cin >> a[i];
bool q = true;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (max(a[i], a[i + 1]) < max(a[j], a[j + 1]) &&
min(a[i], a[i + 1]) < min(a[j], a[j + 1]) &&
max(a[i], a[i + 1]) > min(a[j], a[j + 1])) {
cout << "yes" << endl;
return 0;
}
}
}
cout << "no";
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
void bs_b8a() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long mod = 1e9 + 7;
long long arr[N];
using namespace std;
int main() {
bs_b8a();
long long ta = 1;
while (ta--) {
long long n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> arr[i];
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - 1; ++j) {
long long x1, x2, y1, y2;
x1 = min(arr[i], arr[i + 1]);
y1 = max(arr[i], arr[i + 1]);
x2 = min(arr[j], arr[j + 1]);
y2 = max(arr[j], arr[j + 1]);
if ((x1 < x2 && x2 < y1 && y1 < y2) ||
(x1 > x2 && y2 < y1 && x1 < y2)) {
cout << "yes\n";
return 0;
}
}
}
cout << "no\n";
return 0;
}
}
| CPP |
358_A. Dima and Continuous Line | 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).
<image>
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).
Examples
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. | 2 | 7 | n = int(input())
points = map(int, raw_input().split())
def getKey(x) :
return x[0]
if n <= 2 :
print "no"
else :
intervals = []
for i in range(1, len(points)) :
a = min(points[i], points[i-1])
b = max(points[i], points[i-1])
intervals.append([a, b])
intervals.sort(key=getKey)
# print intervals
flag = False
for i in range(1, len(intervals)) :
for j in range(0, i) :
if intervals[i][0] < intervals[j][1] and \
intervals[i][0] > intervals[j][0] and \
intervals[i][1] > intervals[j][1] :
flag = True
# print intervals[i]
# print intervals[j]
break
if flag :
print 'yes'
else :
print 'no'
| PYTHON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.