#296 (Div.2) C.glass carving

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Problem-solving ideas: the subject requires every cut, output the current maximum area of glass. The idea of this problem is obvious: after each cut to find the current maximum length, the maximum width, can be multiplied. But the key to the problem is how to quickly find the maximum value.

At first I did not have a good idea, want to use the array, but the total sense of the array is not enough, do not know how to well update the length of the cut after the value, do not know how to quickly find the maximum value. Then think of the STL set, you can put all the cutting position in the set, and then find the maximum value. But the result is inefficient, leading to tle. It dawned on someone else's code: You can directly get rid of the cut line, and add the segment after cutting.

But here comes the question, how do you store these segments? The answer is to use the tag array. If the segment value is present, marked as 1, otherwise marked as 0, it is convenient to update the segment value. It is also convenient to find the longest line segment, because the maximum length is not increased after each cut, so it is only necessary to start from the maximum length before cutting, and to see if it exists.

3. Code:

#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;typedef long long LL; #define N 200000+ 10SET&LT;INT&GT;WD, hd;//records the position of the cut in int W, h, n;set<int>::iterator I, J;int wi[n], and hi[n];//marks the currently existing edge Long value void cut (set <int>&s, int*a, int p) {S.insert (p), i = j = S.find (p); I, ++j,--a[*j-*i];//Remove the separated length/width + + a[p-*i], ++a[*j-p ];//newly produced two long/wide}int main () {//freopen ("T.txt", "R", stdin), while (Cin >> w >> h >> N) {int p, MAXW, Maxh;cha R C;memset (WI, 0, sizeof (WI)), memset (Hi, 0, sizeof (HI)), Wd.clear (), Hd.clear (), Wd.insert (0), Wd.insert (W), Hd.insert (0 ), Hd.insert (h); wi[w] = hi[h] = 1;maxw = W, maxh = H;while (n--) {cin >> C >> p;if (c = = ' V ') cut (WD, WI, p), Else cut (HD, Hi, p), while (!wi[maxw])--maxw;//find the maximum value while (!hi[maxh])--maxh;cout << (LL) Maxh*maxw << Endl;}} return 0;}

#296 (Div.2) C.glass carving

Related Article

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.