广大校赛

A

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
//先考虑3
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int N=5e2+10;
int n,m;
char a[N][N];
int res1=0,res2=0,res3=0;
void check1(int x,int y){
int f=1;
for(int i=0;i<5;i++){
if(a[x+i][y]!='#') f=0;
}
for(int j=1;j<=2;j++){
if(a[x][y+j]!='#') f=0;
if(a[x+2][y+j]!='#') f=0;
}
if(a[x+1][y+2]!='#') f=0;
if(f){
res1++;
for(int i=0;i<5;i++){
a[x+i][y]='.';
}
for(int j=1;j<=2;j++){
a[x][y+j]='.';
a[x+2][y+j]='.';
}
a[x+1][y+2]='.';
}
}
void check2(int x,int y){
int f=1;
for(int i=0;i<5;i++){
if(a[x+i][y+2]!='#') f=0;
}
if(a[x][y]!='#') f=0;
if(a[x][y+1]!='#') f=0;
if(a[x+2][y+1]!='#') f=0;
if(f){
res2++;
for(int i=0;i<5;i++){
a[x+i][y+2]='.';
}
a[x][y]='.';
a[x][y+1]='.';
a[x+2][y+1]='.';
}
}
void check3(int x,int y){
int f=1;
for(int i=0;i<5;i++){
if(a[x+i][y]!='#') f=0;
if(a[x+i][y+2]!='#') f=0;
}
if(a[x][y+1]!='#') f=0;
if(a[x+2][y+1]!='#') f=0;
if(a[x+4][y+1]!='#') f=0;
if(f){
res3++;
for(int i=0;i<5;i++){
a[x+i][y]='.';
a[x+i][y+2]='.';
}
a[x][y+1]='.' ;
a[x+2][y+1]='.' ;
a[x+4][y+1]='.' ;
}
}

signed main()
{
IOS;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
cin>>a[i][j];
}
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++)
{
if(a[i][j]=='#')
{
check3(i,j);//优先考虑,因为符三包含符二和符三
}
if(a[i][j]=='#')
{
check1(i,j);
}
if(a[i][j]=='#')
{
check2(i,j);
}
//每次都判断一下该点
}
}

cout<<res1<<" "<<res2<<" "<<res3<<endl;
return 0;
}

写到这里舍友在打atcoder,于是写了一道B

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
//中途打atcoder的舍友说这题有趣,他wa了两个点
//于是来看看
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
using namespace std;
const int N=1e6+100;
int sum1[N];
int sum2[N];
int main()
{
string s="wbwbwwbwbwbw";
string a=" ";
int x,y;
cin>>x>>y;
rep(i,1,100)
{
a+=s;
}
int t=s.length()-1;
rep(i,1,t*100)
{
if(a[i]=='w')
{
sum1[i]=sum1[i-1]+1;
sum2[i]=sum2[i-1];
}
else
{
sum1[i]=sum1[i-1];
sum2[i]=sum2[i-1]+1;
}
}
rep(i,x+y,t*100-1)
{
if(sum1[i]-sum1[i-x-y]==x&&sum2[i]-sum2[i-x-y]==y)
{cout<<"Yes";return 0;
}
}
cout<<"No";

}

G

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
//一眼二分
//没想到敲一遍就过了
#include<iostream>
#include<vector>
using namespace std;
signed main(){

ios::sync_with_stdio(false);

cin.tie(0);


int n;

cin >> n;

vector<long long> a(n + 2);


for(int i = 1; i <= n; i++){

cin >> a[i];

}

auto check = [&](long long x){

auto b = a;
for(int i = 1; i <= n; i++){

if(x <= b[i]){

return false;

}

x += a[i] / 2;

b[i + 1] += (a[i] + 1) / 2;

}

return true;

};


long long low = 1 , high = 1E9 + 10;

while(low+1 < high){

long long mid = (low + high) / 2;

if(check(mid)){

high = mid;

}else{

low = mid ;

}

}
cout << high << "\n";
}

H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int main()
{
char str[100];
cin.get(str,100);
for (int i = 0;i < 100;i++)
{
if (str[i] == '4')str[i] = 'a';
if (str[i] == '6')str[i] = 'b';
if (str[i] == '3')str[i] = 'e';
if (str[i] == '9')str[i] = 'g';
if (str[i] == '1')str[i] = 'l';
if (str[i] == '0')str[i] = 'o';
if (str[i] == '5')str[i] = 's';
if (str[i] == '7')str[i] = 't';
if (str[i] == '2')str[i] = 'z';
}
cout << str;
}

J

按位搜索,最精华的一部分

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
//这题赛时想了2小时()
//这下必须得补一下按位搜索了
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define frep(i,a,n) for(int i=a;i>=n;i--)
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
vector<vector<int> >a(n+1,vector<int>(m+1));
//习惯用这个把
vector<vector<int> >vis(n+1,vector<int>(m+1));
rep(i,1,n)
{
rep(j,1,m)
{
cin>>a[i][j];
}
}
int ans=0;
frep(i,29,0)
{
rep(i,1,n)
{
rep(j,1,m)
{
vis[i][j]=0;
}
}
int tag=ans+(1<<i);
queue<array<int,2>>que;
if((a[1][1]&tag)==tag)
{
que.push({1,1});
vis[1][1]=1;
}
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
while(que.size())
{
array<int,2>t=que.front();
int x=t[0];
int y=t[1];
que.pop();
rep(i,0,3)
{
int tx=x+dx[i];
int ty=y+dy[i];
bool flag=(tx>=1)&&(tx<=n)&&(ty<=m)&&(ty>=1)&&(vis[tx][ty]==0);
if(flag)
{
if((a[tx][ty]&tag)==tag)
{
vis[tx][ty]=1;
que.push({tx,ty});
}
else
{
vis[tx][ty]=2;
}
}
}
if(vis[n][m]==1)
{
ans|=(1<<i);
}
}
}
cout<<ans<<'\n';



}

K

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
//思路很容易,直接进行模拟即可
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
map<char,int> mp;
string s;
int main(){
int n,ans=0,cur=0;
cin>>n;
cin>>s;
for(int i=0;i<n;i++){
if(cur>0){
cur--;
continue;
}
else{
ans++;
mp[s[i]]++;
if(mp['g']>0&&mp['h']>0&&mp['z']>0&&mp['u']>0){
cur+=mp['g']+mp['h']+mp['z']+mp['u'];
mp['g']=0;
mp['h']=0;
mp['z']=0;
mp['u']=0;
}
}
}
cout<<ans;


return 0;
}

M

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
//赛时这道没出我未免也太胆小了
//明明那么多人过
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define frep(i, a, n) for (int i = a; i >= n; i--)
using ll = long long;
using namespace std;
const int N=1e6+100;
struct node
{
int x,y,cnt;
}a[N];
bool cmp(node a,node b)
{
if(a.y==b.y)
{
return a.x<b.x;
}
return a.y<b.y;
}
int main()
{
int n;
cin>>n;
rep(i,1,n)
{
cin>>a[i].x>>a[i].y;
a[i].cnt=i;
}
sort(a+1,a+1+n,cmp);
cout<<n/2<<'\n';
for(int i=1;i<=n;i+=2)
{
if(i+1>n)
{
break;
}
else
{
cout<<a[i].cnt<<" "<<a[i+1].cnt<<'\n';
}
}


}