cppAcademy
FROM LEARNING TO COMPETING

Real problems.
Your next challenge.

Explore the Group C Olympiad archive.
Choose a topic. Find a challenge. Build your solution.

213 tasks across the Municipal, Regional, and National rounds (2009–2026), plus 4 previously featured problems. 146 tasks have independently written English summaries, analyses, and C++17 solutions; the remaining entries link to Arena. Topic tags are from Arena or our reviewed explanations. Difficulty labels are learning estimates, not official ratings.
GROUP C2015 · MediumCircular Intervals

Two Circular Arcs

National Olympiad — Municipal round

Submission name: two.cpp

Problem summary

Each closed arc runs counterclockwise from its first endpoint to its second on one circle. Endpoint angles are whole degrees. Equal endpoints define a single point, not the entire circle. Determine whether two arcs share any point.

Input

Two lines, each containing an arc’s start and end angles.

Output

1 if the arcs intersect, otherwise 0.

Constraints

All angles are integers from 0 to 359 inclusive.

Worked example

An independently prepared example for this explanation.

Input

350 10
10 20

Output

1

Solution analysis

  1. An angle p belongs to arc a→b when its counterclockwise displacement from a is no larger than that of b.
  2. Two closed arcs intersect if an endpoint of either lies on the other. Test all four endpoints.

Why it works

Disjoint endpoints with a nonempty intersection would require the arcs to overlap without entering or leaving each other, impossible for proper closed arcs; singleton arcs are covered by the same containment test.

Complexity: O(1) time and space.

Watch out. Include touching endpoints and wraparound through zero.

Commented C++17 solution

An independently written complete program with standard headers.

// Key idea: Disjoint endpoints with a nonempty intersection would require the arcs to overlap without
// entering or leaving each other, impossible for proper closed arcs; singleton arcs are covered by the
// same containment test.
#include<iostream>
using namespace std;
bool inside(int a,int b,int p){
    return (p-a+360)%360<=(b-a+360)%360;
}
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(inside(a,b,c)||inside(a,b,d)||inside(c,d,a)||inside(c,d,b))<<'\n';
}

Source: Arena Olimpiici ↗