Hdu1542 line segment tree + scanning line + discretization

Source: Internet
Author: User

I just want to say whether the question is actually unacceptable or not. I suggest you refer to the one I wrote earlier.



# Include <stdio. h>

# Include <string. h>
# Include <algorithm>
# Include <iostream>
Using namespace STD;
# Define LL (x) (x <1)
# Define RR (x) (x <1) | 1)


Int N;
Struct Node
{
Double Y;
Int x1, x2;
Int flash;
} A [31000];
Struct Node
{
Int II;
Double X;
} Change [1, 35000];
Int CMP1 (node A, Node B)
{
Return A. x <B. X;
}
Int cmp2 (node A, Node B)
{
Return A. Y <B. Y;
}
Int num [80000];
Double map [31000];
Int Update (int l, int R, int left, int right, int K, int mark)
{
Int mid = (L + r)/2;
If (L = left & Right = r)
{
If (Num [Mark]! =-1)
{
Num [Mark] + = K;
Return 0;
}
Update (L, mid, L, mid, K, LL (Mark ));
Update (MID, R, mid, R, K, RR (Mark ));
If (Num [LL (Mark)] = num [RR (Mark)]) num [Mark] = num [LL (Mark)];
Else num [Mark] =-1;
}
Else
{
If (Num [Mark]> = 0)
{
Num [LL (Mark)] = num [RR (Mark)] = num [Mark];
}
If (right <= mid)
{
Update (L, mid, left, right, K, LL (Mark ));
}
Else if (left> = mid)
{
Update (MID, R, left, right, K, RR (Mark ));
}
Else
{
Update (L, mid, left, mid, K, LL (Mark ));
Update (MID, R, mid, right, K, RR (Mark ));
}
If (Num [LL (Mark)] = num [RR (Mark)]) num [Mark] = num [LL (Mark)];
Else num [Mark] =-1;
}
Return 0;
}
Double find (int l, int R, int mark)
{
Double long = 0;
If (Num [Mark]> = 1)
{
Long + = map [R]-map [l];
Return long;
}
If (Num [Mark] = 0) return 0;
Int mid = (L + r)/2;
Long + = find (L, mid, LL (Mark) + find (MID, R, RR (Mark ));
Return long;
}
Int main ()
{
Int I, j, D = 1;
Double X1, Y1, X2, Y2;
While (~ Scanf ("% d", & N), n)
{
N * = 2;
// J = 0;
Memset (A, 0, sizeof ());
Memset (MAP, 0, sizeof (MAP ));
Memset (change, 0, sizeof (Change ));
For (I = 1; I <= N; I + = 2)
{
Scanf ("% lf", & X1, & Y1, & X2, & Y2 );
A [I]. Y = Y1;
A [I]. Flash = 1;
A [I + 1]. Y = Y2;
A [I + 1]. Flash =-1;
Change [I]. x = x1;
Change [I + 1]. II = change [I]. II = I;
Change [I + 1]. x = x2;
}
Int leap [10000];
Memset (LEAP, 0, sizeof (LEAP ));
Sort (Change + 1, change + 1 + N, CMP1 );
Int J = 0;
Double K =-1;
For (I = 1; I <= N; I ++)
{
If (change [I]. X! = K)
{
K = change [I]. X;
++ J;
Map [J] = change [I]. X;
}
If (LEAP [change [I]. ii] = 0)
{
A [change [I]. II]. X1 = A [change [I]. II + 1]. X1 = J;
Leap [change [I]. ii] = 1;
}
Else a [change [I]. II]. X2 = A [change [I]. II + 1]. X2 = J;
}
Sort (a + 1, A + 1 + N, cmp2 );
Memset (Num, 0, sizeof (Num ));
Update (1, J, a [1]. X1, a [1]. X2, 1, 1 );
Double area = 0;
For (I = 2; I <= N; I ++)
{
Area + = find (1, J, 1) * (a [I]. Y-A [I-1]. y );
If (A [I]. Flash = 1)
Update (1, J, a [I]. X1, a [I]. X2, 1, 1 );
Else update (1, J, a [I]. X1, a [I]. X2,-1, 1 );
}
Printf ("Test Case # % d \ n", d ++ );
Printf ("total received area: %. 2lf \ n", area );
Printf ("\ n ");
}
Return 0;
}

Hdu1542 line segment tree + scanning line + discretization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.