Vijos 1055 ♂ Method of maximal sub-matrix of cow bath ①

Source: Internet
Author: User

Test Instructions:Link Method:The calculation ♂ method of maximal sub-matrix ① parsing:First of all, when it comes to the maximal sub-matrix, we might think about building a house before? , the problem of the DP solution. However, this topic certainly has a higher ♂-end algorithm. For example, the algorithm ① to be discussed next. Let's look at the data range first, n,m<=30000, this is finished, how DP? Suddenly d dropped your original algorithm, really not easy face. So let's introduce a new algorithm. First of all talk about violence, enumerate all kinds of bad points, but this kind of complexity? Can even reach 6 times, so how to optimize it? According to experience, this kind of coordinate chart can lower the complexity of the order. So God Ben introduced the algorithm of s^2 complexity, where s is the number of bad points. First, we sort all the bad points by the x first keyword, y second keyword, and then we enumerate the benchmark bad points, which are the bad points on the left edge. Suppose the initial upper boundary is the highest row and the bottom boundary is the lowest row. Then scan all the bad points on the right side. Each sweep to a point, we know that the two horizontal gap multiplied by the upper and lower boundary gap is the current area of a maximal sub-matrix. After the answer has been updated, you also need to update the upper and lower bounds, for the subject (that is, the bad point can exist at the boundary), when the bad point at the point of the enumeration (in the same row), if the bad point is lower than the current upper bounds, you need to update the upper boundary, to ensure that after the bad point is enumerated to the maximum sub-matrix The next frontier is discussed in the same vein. At the end of each enumeration, do not forget to update the case that contains the boundary. Of course, we have found that if we enumerate from right to left, there is no case of a left boundary (except for a point at the left edge), so we need to enumerate from right to left in order not to omit the situation. Is this the end of it? And not. The left and right boundaries are not enumerated in the cases that are contained. So we need to deal with the situation of the left and right boundaries, and I'm going to do it again in order of Y. And then the water is over ~ Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 5010using namespace Std;intL,w,n;struct node{int x,y;} Pt[n];intCMP (node A,node b) {if(A.x==b.x)returnA.y<b.y;returnA.x<b.x;}intCMP2 (node A,node b) {if(A.y==b.y)returnA.x<b.x;returnA.y>b.y;}intMain () {scanf (" %d%d%d", &l,&w,&n);if(!n) {printf("%d\ n", l*w);return 0;} for(intI=1; i<=n;i++) scanf ("%d%d", &pt[i].x, &pt[i].y);Sort(pt+1, pt+n+1, CMP);intans=-1; for(intI=1; i<=n;i++) {intU=w,d=0; for(intj=i+1; j<=n;j++) {Ans=max (ans, (pt[j).x-pt[i].x)*(u-d));if(Pt[j].y>=pt[i].y) U=min (U,pt[j].y);if(Pt[j].y<=pt[i].y) D=max (D,pt[j].y); } Ans=max (ans, (l-pt[i).x)*(u-d)); } for(inti=n;i>=1; i--) {intU=w,d=0; for(intj=i-1; j>=1; j--) {Ans=max (ans, (pt[i).x-PT[J].x)*(u-d));if(Pt[j].y>=pt[i].y) U=min (U,pt[j].y);if(Pt[j].y<=pt[i].y) D=max (D,pt[j].y); } Ans=max (Ans,pt[i].x*(u-d)); }Sort(pt+1, pt+n+1, CMP2); for(intI=1; i<n;i++) {Ans=max (ans, (pt[i).y-pt[i+1].y)*l); } Ans=max (ans, (w-pt[1].y)*l); Ans=max (Ans,pt[n].y*l);printf("%d\ n", ans); }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Vijos 1055 ♂ Method of maximal sub-matrix of cow bath ①

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.