Defense Construction bzoj 2300, bzoj2300

Source: Internet
Author: User

Defense Construction bzoj 2300, bzoj2300

Defense Construction (1 s 512 MB) defense

[Problem description]

Recently, conflicts between country A and country B have intensified. In order to prevent unexpected events, Country A is preparing to build A long line of defense. Of course, if A line of defense is built, the city to be protected must be built inside the line of defense. However, the upper layer of country A is still hesitant. Which cities should be used as protection targets? Due to the limited funding of country A, I hope you can help with the following tasks:

1. Give the coordinates of all your country A Cities

2. After discussion on the upper layer of country A, considering the economic issue, the company decided to cancel the protection for city I, that is, city I does not need to be protected by the defense line.

3. Ask the upper layer of country A about the minimum total cost of building defense lines for the remaining cities to be protected.

You need to answer each query. Note that the defense cost per unit 1 is 1.

The terrain of country A is like this. The X axis is A river, which is equivalent to A natural line of defense. You do not need to build it again.

Country A always has two cities by the river. One is (0, 0) and the other is (n, 0). the abscissa of all other points is greater than 0 and less than n, the ordinate values are greater than 0. A is not in the capital of (0, 0) and (n, 0.

The three cities (0, 0), (n, 0) and capital must be protected.

In, A, B, C, D, E point for the city of A, and currently all want to protect, then the construction of the line of defense will be A-B-C-D, the cost is the length of the Line AB + the length of the Line BC + the length of the line CD

If point B's protection is revoked at this time, the defense will become

[Input format]

In the first row, the three integers n, x, and y indicate the riverside cities and capitals (0, 0), (n, 0), (x, y) respectively ).

The second row is an integer m.

In the next m row, each row has two integers, a and B, indicating that the coordinates of A non-capital non-riverside city in country a are (a, B ).

The next integer q represents the total number of modifications and inquiries.

Next, each row in the q row is either 1 I or 2, indicating that the protection and inquiry of the I city are revoked.

[Output format]

One row is output for each query. A real number v indicates the cost of building the defense line. two decimal places are reserved.

[Example input]

4 2 1

2

1 2

3 2

5

2

1 1

2

1 2

2

[Sample output]

6.47

5.84

4.47

[Data Scope]

30% of Data m <= 1000, q <= 1000

100% of Data m <= 100000, q <= 200000, n> 1

The coordinates of all vertices are within 10000, and the data guarantee has no focus.

 

Question:

Main algorithms: Set; calculation ry; fast sorting;

The question is to support deleting points to maintain an upper Convex Shell.

Because only the delete point operation is supported

In this case, the offline reverse processing becomes a bit operation.

If you want to add a point in a convex hull, You can discard it ······

If this point is outside the convex hull

Consider the points on the left and right sides respectively.

Maintain convex hull in two directions

This process is implemented using set.

  1 #include<algorithm>  2 #include<iostream>  3 #include<cstring>  4 #include<cstdlib>  5 #include<cstdio>  6 #include<cmath>  7 #include<set>  8 using namespace std;  9 inline int Get() 10 { 11     int x = 0; 12     char c = getchar(); 13     while('0' > c || c > '9') c = getchar(); 14     while('0' <= c && c <= '9') 15     { 16         x = (x << 3) + (x << 1) + c - '0'; 17         c = getchar(); 18     } 19     return x; 20 } 21 const int me = 200233; 22 int n, m, x, y, e; 23 int nu; 24 double sum; 25 struct dot 26 { 27     int x, y; 28     inline bool operator < (const dot &z) const 29     { 30         if(x != z.x) return x < z.x; 31         return y < z.y; 32     } 33 }; 34 dot o; 35 dot a[me]; 36 int flag[me]; 37 bool vis[me]; 38 int num[me]; 39 double ans[me]; 40 multiset<dot> c; 41 inline double Dis(const int &ax, const int &ay, const int &bx, const int &by) 42 { 43     return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)); 44 } 45 inline int Cross(const int &ax, const int &ay, const int &bx, const int &by) 46 { 47     return ax * by - bx * ay; 48 } 49 inline void Add(dot v) 50 { 51     multiset<dot>::iterator l = c.upper_bound(v), r = l; 52     --l; 53     if(Cross((r -> x) - (l -> x), (r -> y) - (l -> y), v.x - (l -> x), v.y - (l -> y)) <= 0) return; 54     sum -= Dis((l -> x), (l -> y), (r -> x), (r -> y)); 55     multiset<dot>::iterator now; 56     while(l != c.begin()) 57     { 58         now = l; 59         --l; 60         if(Cross(v.x - (l -> x), v.y - (l -> y), (now -> x) - (l -> x), (now -> y) - (l -> y)) >= 0) 61         { 62             ++l; 63             break; 64         } 65         sum -= Dis((now -> x), (now -> y), (l -> x), (l -> y)); 66         c.erase(now); 67     } 68     while(true) 69     { 70         now = r; 71         ++r; 72         if(r == c.end()) 73         { 74             --r; 75             break; 76         } 77         if(Cross(v.x - (r -> x), v.y - (r -> y), (now -> x) - (r -> x), (now -> y) - (r -> y)) <= 0) 78         { 79             --r; 80             break; 81         } 82         sum -= Dis((now -> x), (now -> y), (r -> x), (r -> y)); 83         c.erase(now); 84     } 85     c.insert(v); 86     sum += Dis((l -> x), (l -> y), v.x, v.y) + Dis(v.x, v.y, (r -> x), (r -> y)); 87 } 88 int main() 89 { 90     o.x = o.y = 0;  91     c.insert(o); 92     o.x = n = Get(); 93     c.insert(o); 94     o.x = x = Get(); 95     o.y = y = Get(); 96     c.insert(o); 97     m = Get(); 98     sum = Dis(0, 0, x, y) + Dis(x, y, n, 0); 99     for(int i = 1; i <= m; ++i)100     {101         a[i].x = Get();102         a[i].y = Get();103     }104     e = Get();105     for(int i = 1; i <= e; ++i)106     {107         flag[i] = Get();108         if(flag[i] == 1)109         {110             num[i] = Get();111             vis[num[i]] = true;112         }113     }114     for(int i = 1; i <= m; ++i)115         if(!vis[i])116             Add(a[i]);117     for(int i = e; i >= 1; --i)118     {119         if(flag[i] == 1) Add(a[num[i]]);120         else ans[++nu] = sum;121     }122     for(int i = nu; i >= 1; --i)123         printf("%.2lf\n", ans[i]);124 }

 

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.