5945: interval coverage problems
With N closed interval [Ai, Bi] number line, the selection interval covered as little as possible to specify a segment [S, T].
Entry
The first line contains three integers N (1 <= N <= 10 ^ 5), S and T (-10 ^ 6 <= S <T <= 10 ^ 6)
Next N lines of two integers Ai, Bi (-10 ^ 6 <= Ai <Bi <10 ^ 6)
Export
Output contains an integer representing the number of a minimum required interval. If no solution, output No Solution
Sample input
8 1 10
-3 -1
13 16
0 3
2 6
3 5
6 10
5 6
4 10
Sample Output
3
Data input in accordance with the left point of ordering initialize a reference point for the need to cover the left point range than the reference point to find the left and right end points a little larger than the reference point to find the right point of maximum range of updated reference point in these intervals inside
#include <bits/stdc++.h> using namespace std; struct jilu { int l,r; }a[100010]; bool cmp(jilu a,jilu b) { return a.l<b.l; } int main() { int n,s,t,sum=0,f=1; cin>>n>>s>>t; for(int i=0;i<n;i++) { cin>>a[i].l>>a[i].r; } sort(a,a+n-, CMP); int jidian = S, = maxrl - 0x3f3f3f3f3f3f , F1 = 0 ; // this maxrl very beginning of the pit is provided a 0WA twice .. for ( int I = 0 ; I <n-; I ++ ) { IF (jidian> = T) BREAK ; IF (A [I] .L <= jidian && A [I] .r> jidian) { maxrl = max (maxrl, A [I] .r); F1 = . 1 ; } IF ( A [I] .L> jidian && F1 == 0 ) { BREAK ; F= 0 ; } the else IF (A [I] .L> == jidian && F1 . 1 ) { SUM ++ ; jidian = maxrl; I - ; maxrl = - 0x3f3f3f3f3f3f ; F1 = 0 ; } the else IF (I == N- 1 ) // need to update the exit { SUM ++ ; jidian = maxrl; } } IF(f!=0&&jidian>=t) cout<<sum<<endl; else cout<<"No Solution"<<endl; }