1007: [HNOI2008] horizontal visible straight line
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 1830 Solved: 656
[Submit] [Status] [Discuss]
Description
Input
First Act N (0 <N <50000), then input Ai, Bi
Output
Numbers of lines visible from small to large output, separated by spaces in the middle. A space must be placed after the last number.
Sample Input
3
-1 0
1 0
0 0
Sample Output
1 2
Sort by slope and insert data from small to large.
Special circumstances of semi-plane intersection:
Each time
Make sure that the x coordinates are <x, top >>< top, top '>. Otherwise, the top is invisible (top is the top element of the stack)
[Cpp]
# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <algorithm>
# Include <functional>
# Include <iostream>
Using namespace std;
# Define MAXN (50000 + 10)
Int n;
Struct line
{
Int k, B, I;
Friend bool operator <(line a, line B) {return (a. k = B. k )? A. B> B. B: a. k <B. k ;}
Friend double intx (line a, line B)
{
Return (double) (B. b-a. B)/(a. k-b.k );
}
} A [MAXN];
Int s [MAXN], size = 0;
Void push (int x)
{
While (size> 1 & intx (a [s [size], a [s [size-1])> = intx (a [s [size], a [x]) size --;
S [++ size] = x;
}
Bool B [MAXN];
Int main ()
{
Scanf ("% d", & n );
For (int I = 1; I <= n; I ++) {scanf ("% d", & a [I]. k, & a [I]. b); a [I]. I = I ;}
Sort (a + 1, a + 1 + n );
Push (1 );
For (int I = 2; I <= n; I ++)
If (a [I]. k> a [I-1]. k) push (I );
// For (int I = 1 ;)
Memset (B, 0, sizeof (B); for (int I = 1; I <= size; I ++) B [a [s [I]. i] = 1;
For (int I = 1; I <= n; I ++) if (B [I]) cout <I <'';
Return 0;
}
# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <algorithm>
# Include <functional>
# Include <iostream>
Using namespace std;
# Define MAXN (50000 + 10)
Int n;
Struct line
{
Int k, B, I;
Friend bool operator <(line a, line B) {return (a. k = B. k )? A. B> B. B: a. k <B. k ;}
Friend double intx (line a, line B)
{
Return (double) (B. b-a. B)/(a. k-b.k );
}
} A [MAXN];
Int s [MAXN], size = 0;
Void push (int x)
{
While (size> 1 & intx (a [s [size], a [s [size-1])> = intx (a [s [size], a [x]) size --;
S [++ size] = x;
}
Bool B [MAXN];
Int main ()
{
Scanf ("% d", & n );
For (int I = 1; I <= n; I ++) {scanf ("% d", & a [I]. k, & a [I]. b); a [I]. I = I ;}
Sort (a + 1, a + 1 + n );
Push (1 );
For (int I = 2; I <= n; I ++)
If (a [I]. k> a [I-1]. k) push (I );
// For (int I = 1 ;)
Memset (B, 0, sizeof (B); for (int I = 1; I <= size; I ++) B [a [s [I]. i] = 1;
For (int I = 1; I <= n; I ++) if (B [I]) cout <I <'';
Return 0;
}