Occlusion judgment
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 659 Accepted Submission (s): 197
Problem Description
There is a row of stone pillars arranged along the east and west directions on a square, and the sun emits light at a certain angle (parallel light) from the east ). Some pillars may be completely blocked by the shadows of the tall pillars on the east side. The problem you need to solve now is to find out how many columns are not completely blocked.
Assume that each stone pillar is a fine rod and is placed perpendicular to the ground.
Input
The input contains multiple groups of data. The first row of each group of data is an integer N (0 <N <= 100000), indicating the number of columns. N = 0 indicates that the input is complete. Next there are N rows, each row is two integers, respectively given the horizontal position X and height H of each column (the greater X, the more in the West, 0 <= X <= 0000000,0 <H <= 10000000 ensure that there are no two columns in the same X coordinate ). There is A last line that returns the tangent T/A (1 <= A, T <= 10) of the angle between the sun and the ground in the form of A fraction ).
Output
For each group of data, the output contains a row of the number.
Sample Input
4
0 3
3 1
2 2
1 1
1/1
0
Sample Output
2
Tip:
There are a lot of input data. Use scanf instead of cin.
Source
UESTC 6th Programming Contest Online
Recommend
Lcy
Idea: each pillar will emit a range on the X axis, so you only need to check the number of contained intervals and subtract the total number of included intervals.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Struct haha
{
Double s;
Double h;
Double e;
} A [111111];
// Bool vis [10000000 + 100];
Int cmp (const void * a, const void * B)
{
Return (* (struct haha *) a). s> (* (struct haha *) B). s? 1:-1;
}
Int main ()
{
Int n, I, j;
While (scanf ("% d", & n )! = EOF)
{
If (! N) break;
Double tan, c, B;
For (I = 0; I <n; I ++)
Scanf ("% lf", & a [I]. s, & a [I]. h );
Scanf ("% lf/% lf", & c, & B );
Tan = c/B;
// Printf ("% lf \ n", tan );
Qsort (a, n, sizeof (a [0]), cmp );
For (I = 0; I <n; I ++)
{
A [I]. e = a [I]. s + a [I]. h/tan;
// Printf ("s = % lf e = % lf \ n", a [I]. s, a [I]. e );
}
Int cnt = n;
Double s, e;
S = a [0]. s; e = a [0]. e;
For (I = 1; I <n; I ++)
{
If (a [I]. e <= e & a [I]. s> = s) cnt --;
Else
{
If (a [I]. e> e) {e = a [I]. e; s = a [I]. s ;}
}
}
Printf ("% d \ n", cnt );
}
Return 0;
}
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Struct haha
{
Double s;
Double h;
Double e;
} A [111111];
// Bool vis [10000000 + 100];
Int cmp (const void * a, const void * B)
{
Return (* (struct haha *) a). s> (* (struct haha *) B). s? 1:-1;
}
Int main ()
{
Int n, I, j;
While (scanf ("% d", & n )! = EOF)
{
If (! N) break;
Double tan, c, B;
For (I = 0; I <n; I ++)
Scanf ("% lf", & a [I]. s, & a [I]. h );
Scanf ("% lf/% lf", & c, & B );
Tan = c/B;
// Printf ("% lf \ n", tan );
Qsort (a, n, sizeof (a [0]), cmp );
For (I = 0; I <n; I ++)
{
A [I]. e = a [I]. s + a [I]. h/tan;
// Printf ("s = % lf e = % lf \ n", a [I]. s, a [I]. e );
}
Int cnt = n;
Double s, e;
S = a [0]. s; e = a [0]. e;
For (I = 1; I <n; I ++)
{
If (a [I]. e <= e & a [I]. s> = s) cnt --;
Else
{
If (a [I]. e> e) {e = a [I]. e; s = a [I]. s ;}
}
}
Printf ("% d \ n", cnt );
}
Return 0;
}