-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.31largesetrect.cpp
56 lines (56 loc) · 893 Bytes
/
7.31largesetrect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string.h>
using namespace std;
int rect[4][6]={
{1,1,0,0,1,0},
{0,1,1,1,1,1},
{1,1,1,1,1,0},
{0,0,1,1,0,0}
};
int nrect[4][6];
int largestarea(int x,int y)
{
memcpy(nrect,rect,sizeof(int)*x*y);
int largest=0;
int *stack = new int[y];
for(int i=1;i<x;i++)
for(int j=0;j<y;j++)
{
if(nrect[i-1][j] != 0&&nrect[i][j]!= 0)
nrect[i][j] = nrect[i-1][j]+1;
}
for(int i = 0;i<x;i++)
{
stack[0] = nrect[i,0];
int k = 0,highest = stack[0];
for(int j= 1;j<y;j++)
{
if(nrect[i][j]>stack[k])
{
k+=1;
stack[k] = nrect[i][j];
}
else if(nrect[i][j]==stack[k])
{
k+=1;
stack[k] = nrect[i][j];
}
else
{
while(k>0&&stack[k]>nrect[i][j])
{
k--;
}
}
}
}
}
int main()
{
// for(int i = 0;i<4;i++)
// { for(int j=0;j<6;j++)
// cout <<nrect[i][j]<<" ";
// cout << endl;
// }
return 0;
}