25.3.19刷题

本文最后更新于 2025年3月19日 晚上

P1328 生活大爆炸版石头剪刀布

https://www.luogu.com.cn/problem/p1328

题解

模拟

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
#include<bits/stdc++.h>
using namespace std;

int n,na,nb;
int a[200],b[200];
int win[5][5]={
{0,2,1,1,2},
{1,0,2,1,2},
{2,1,0,2,1},
{2,2,1,0,1},
{1,1,2,2,0}
};



int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

cin>>n>>na>>nb;
for(int i=0;i<na;i++)
{
cin>>a[i];
}
for(int i=0;i<nb;i++)
{
cin>>b[i];
}


int numa=0,numb=0;

for(int i=0;i<n;i++)
{
int result=win[a[i%na]][b[i%nb]];

if(result==1)numa++;
else if(result==2) numb++;


}

cout<<numa<<' '<<numb<<endl;

return 0;
}

P1518 两只塔姆沃斯牛 The Tamworth Two

https://www.luogu.com.cn/problem/p1518

题解:

模拟。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
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
#include<bits/stdc++.h>
using namespace std;

char m[12][12];
int f[3],c[3],ans;

void move(int x,int y,int mi,int h)
{
if(mi==0)
{
if(m[x-1][y]=='*')
{
if(h==0) f[2]=1;
else c[2]=1;
}
else
{
if(h==0) f[0]--;
else c[0]--;
}
}
else if(mi==1)
{
if(m[x][y+1]=='*')
{
if(h==0) f[2]=2;
else c[2]=2;
}
else
{
if(h==0) f[1]++;
else c[1]++;
}
}
else if(mi==2)
{
if(m[x+1][y]=='*')
{
if(h==0) f[2]=3;
else c[2]=3;
}
else
{
if(h==0) f[0]++;
else c[0]++;
}
}
else
{
if(m[x][y-1]=='*')
{
if(h==0) f[2]=0;
else c[2]=0;
}
else
{
if(h==0) f[1]--;
else c[1]--;
}
}
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

for(int i=0;i<12;i++) m[i][0]='*',m[i][11]='*';
for(int i=1;i<12;i++) m[0][i]='*',m[11][i]='*';
for(int i=1;i<11;i++)
{
for(int j=1;j<11;j++)
{
cin>>m[i][j];
if(m[i][j]=='C') c[0]=i,c[1]=j,c[2]=0;
if(m[i][j]=='F') f[0]=i,f[1]=j,f[2]=0;
}
}

while((f[0]!=c[0]||f[1]!=c[1])&&ans<200000)
{
ans++;
if(f[0]==c[0]&&f[1]==c[1]) break;
move(f[0],f[1],f[2],0);
move(c[0],c[1],c[2],1);


}

if(ans==200000) cout<<0;
else cout<<ans;
return 0;
}

P1067 多项式输出

https://www.luogu.com.cn/problem/p1067

题解:

模拟。

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
#include<bits/stdc++.h>
using namespace std;

int n;

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

cin>>n;

for(int i=n;i>=0;i--)
{
int a;cin>>a;
if(a)
{
if(n!=i&&a>0) cout<<'+';
if(i!=0&&a==-1) cout<<'-';
if(abs(a)>1&&i!=0) cout<<a;
if(i>1) cout<<"x^"<<i;
if(i==1) cout<<'x';
if(i==0) cout<<a;
}
}

return 0;
}

25.3.19刷题
https://chasehl.github.io/2025/03/19/25.3.19刷题/
作者
Chase King
发布于
2025年3月19日
更新于
2025年3月19日
许可协议