CodeForces-Round#684-Div.2

本文最后更新于:2020年11月20日 下午

A. Buy the String

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
#include<iostream>
#include<cstdio>

using namespace std;

char c[1005];

int main(){
int T;
int sum_1=0,sum_0=0,ans;
cin>>T;
while(T--)
{
int n,c0,c1,h;
cin>>n>>c0>>c1>>h;
for(int i=0;i<n;i++)
{
cin>>c[i];
if(c[i]=='1') sum_1++;
else sum_0++;
}
//cout<<sum_0<<endl<<sum_1<<endl;
ans=c0*sum_0+c1*sum_1;
/*if(c0==c1)
ans=c0*sum_0+c1*sum_1;
if(c0>c1)
ans=min((c1*(sum_1+sum_0))+sum_0*h, ans);
if(c0<c1)
ans=min(c0*(sum_1+sum_0)+sum_1*h, ans);*/
for(int i=1;i<=sum_0;i++)
{
int now=(i*h)+((sum_1+i)*c1)+(sum_0-i)*c0;
ans=min(ans, now);
}
for(int i=1;i<=sum_1;i++)
{
int now=(i*h)+((sum_0+i)*c0)+(sum_1-i)*c1;
ans=min(ans, now);
}
cout<<ans<<endl;
ans=0; sum_1=0; sum_0=0;
}
}

B. Sum of Medians

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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

char c[1005];

int main(){
int T;
int sum_1=0,sum_0=0,ans;
cin>>T;
while(T--)
{
int n,k;
cin>>n>>k;
int m=n*k;
vector<int>a(m);
for(int i=0;i<m;i++)
{
cin>>a[i];
}
long long tot=0;
if(n==2)
{
for(int i=0;i<m;i+=2)
tot+=a[i];
cout<<tot<<endl;
continue;
}
int inter=(n+1)/2;
int left=n-inter;
left+=1;
int x=1,in=0;
for(int i=m-1;i>=0;i--)
{
if(x%left==0)
{
tot+=a[i];
in++;
}
x+=1;
if(in>=k) break;
}
cout<<tot<<endl;
}
return 0;
}

C1. Binary Table (Easy Version)

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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

void case4(vector<vector<int>>&b , vector<string>& a , int i , int j){
a[i][j]=a[i+1][j]=a[i][j+1]=a[i+1][j+1]='0';
vector<int>c;
c.push_back(i);
c.push_back(j);
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
c.clear();
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
c.clear();
c.push_back(i);
c.push_back(j);
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j);
b.push_back(c);
c.clear();
c.push_back(i);
c.push_back(j);
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
}

void case1(vector<vector<int>>&b , vector<string>& a , int i , int j){
vector<int>c;
if(a[i][j]=='1'){
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
}
if(a[i][j+1]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
}
if(a[i+1][j]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
}
if(a[i+1][j+1]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i+1);
c.push_back(j);
c.push_back(i);
c.push_back(j+1);
b.push_back(c);
}
}

void case2(vector<vector<int>>&b , vector<string>& a , int i , int j){
vector<int>c;
if(a[i][j]=='1' && a[i][j+1]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
a[i][j]=a[i][j+1]='0';
a[i+1][j+1]='1';
}
if(a[i][j]=='1' && a[i+1][j]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
b.push_back(c);
a[i][j]=a[i+1][j]='0';
a[i+1][j+1]='1';
}
if(a[i][j]=='1' && a[i+1][j+1]=='1'){
c.push_back(i);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j);
b.push_back(c);
a[i][j]=a[i+1][j+1]='0';
a[i+1][j]='1';
}
if(a[i][j+1]=='1' && a[i+1][j]=='1'){
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j);
c.push_back(i);
c.push_back(j);
b.push_back(c);
a[i][j+1]=a[i+1][j]='0';
a[i][j]='1';
}
if(a[i][j+1]=='1' && a[i+1][j+1]=='1'){
c.push_back(i);
c.push_back(j+1);
c.push_back(i+1);
c.push_back(j+1);
c.push_back(i);
c.push_back(j);
b.push_back(c);
a[i][j+1]=a[i+1][j+1]='0';
a[i][j]='1';
}
if(a[i+1][j]=='1' && a[i+1][j+1]=='1'){
c.push_back(i+1);
c.push_back(j);
c.push_back(i+1);
c.push_back(j+1);
c.push_back(i);
c.push_back(j);
b.push_back(c);
a[i+1][j]=a[i+1][j+1]='0';
a[i][j]='1';
}
}

void solve(){
int n,m;
cin>>n>>m;
vector<string>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
vector<vector<int>>b;
for(int i=0;i<n-1;i++){
for(int j=0;j<m-1;j++){
int total=0;
total=(a[i][j]-'0')+(a[i][j+1]-'0')+(a[i+1][j]-'0')+(a[i+1][j+1]-'0');
if(total==0)
continue;
else if(total==3){
vector<int>c;
if(a[i][j]=='1'){
a[i][j]='0';
c.push_back(i);
c.push_back(j);
}
if(a[i][j+1]=='1'){
a[i][j+1]='0';
c.push_back(i);
c.push_back(j+1);
}
if(a[i+1][j]=='1'){
a[i+1][j]='0';
c.push_back(i+1);
c.push_back(j);
}
if(a[i+1][j+1]=='1'){
a[i+1][j+1]='0';
c.push_back(i+1);
c.push_back(j+1);
}
b.push_back(c);
}
else if(total==4){
case4(b,a,i,j);
}
else if(total==1){
case1(b,a,i,j);
case4(b,a,i,j);
}
else{
case2(b,a,i,j);
case1(b,a,i,j);
case4(b,a,i,j);
}
}
}
cout<<(int)b.size()<<"\n";
for(int i=0;i<(int)b.size();i++){
for(int j=0;j<6;j++)
cout<<b[i][j]+1<<" ";
cout<<"\n";
}
}

int main(){
int T;
cin>>T;
while(T--)
{
solve();
}
return 0;
}

PS.这个模拟把人写傻了


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!