-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSURCHESS.cpp
More file actions
134 lines (117 loc) · 2.95 KB
/
SURCHESS.cpp
File metadata and controls
134 lines (117 loc) · 2.95 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,m;
cin>>n>>m;
int chess[n][m];
char set1[m];
for(i=0;i<n;i++)
{
cin>>set1;
for(int j=0;j<m;j++)
chess[i][j]=(int)(set1[j]-'0');
}
int maxsize=min(m,n);
int x=0,j;
int y=0;
vector<int> v1,v2,v3;
int currentsize=maxsize;
for(;;)
{
int replaceit=0;
for(i=x;i<x+currentsize;i++)
{ int currentvalue=((i+y)%2==0)?1:0;
for(j=y;j<y+currentsize;j++)
{
if(chess[i][j]==currentvalue);
else
replaceit++;
// cout<<"current value is"<<currentvalue<<"\n";
currentvalue=(++currentvalue)%2;
}
}
//cout<<"x is"<<x<<"\n";
//cout<<"y is"<<y<<"\n";
//cout<<"replaceit is"<<replaceit<<"\n";
v1.push_back(replaceit);
y++;
if(y+currentsize>m)
{
y=0;
x++;
if(x+currentsize>n)
{
currentsize--;
x=0;
y=0;
sort(v1.begin(),v1.end());
v2.push_back(*v1.begin());
v1.clear();
if(currentsize==0)
break;
}
}
}
v1.clear();
x=0;
y=0;
currentsize=maxsize;
for(;;)
{
int replaceit=0;
for(i=x;i<x+currentsize;i++)
{ int currentvalue=((i+y)%2==0)?0:1;
for(j=y;j<y+currentsize;j++)
{
if(chess[i][j]==currentvalue);
else
replaceit++;
//cout<<"current value is"<<currentvalue<<"\n";
currentvalue=(++currentvalue)%2;
}
}
//cout<<"x is"<<x<<"\n";
//cout<<"y is"<<y<<"\n";
//cout<<"replaceit is"<<replaceit<<"\n";
v1.push_back(replaceit);
y++;
if(y+currentsize>m)
{
y=0;
x++;
if(x+currentsize>n)
{
currentsize--;
x=0;
y=0;
sort(v1.begin(),v1.end());
v3.push_back(*v1.begin());
v1.clear();
if(currentsize==0)
break;
}
}
}
int q;
vector<int>::iterator it;
vector<int>::iterator it2;
//for(it=v2.begin();it!=v2.end();it++)
// cout<<"--"<<*it<<"\n";
cin>>q;
int f[q];
for(int l=0;l<q;l++)
cin>>f[l];
sort(v2.begin(),v2.end());
sort(v3.begin(),v3.end());
int l=0;
int c;
while(q--)
{ c=f[l];
it=upper_bound(v2.begin(),v2.end(),c);
it2=upper_bound(v3.begin(),v3.end(),c);
cout<<max(it-v2.begin(),it2-v3.begin())<<"\n";
//cout<<it-v2.begin()<<"\n";
l++;
}
}