头部背景图片
Alisa |
Alisa |

code+第三次月赛

jls拉我去打月赛,然后我很显然的挂了,没能骗到衣服qaq(善良的jls送了一件

然后…更更题解?

(我只能把我会做的以及jls教我的题写一写了qaq

以下题目均来自 : https://cp.thusaac.org/contests/5a94ca8896b671ec34244d9a

A

给T组数据,每组给出一个n,接下来给出n个数ai,统计出现最多的数字,如果每个数字出现的次数都一样,输出-1,否则第一行输出出现最多的数字的数量,第二行升序输出出现最多的数字

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
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e6+7;
int b[N],num[N],a[N];

struct aa{
int num,id;
}w[N];
bool cmp(aa a,aa b){
if(a.num==b.num) return a.id>b.id;
return a.num<b.num;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
memset(b,0,sizeof(b));
memset(w,0,sizeof(w));
//memset(num)
int n;
scanf("%d",&n);
for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+n+1);
int cnt=0;
for(int i = 1;i<=n;i++){
if(a[i]!=a[i-1]){
b[++cnt]=a[i];
w[cnt].id=cnt;
}
w[cnt].num++;
}
sort(w+1,w+cnt+1,cmp);
if(w[1].num==w[cnt].num){
printf("-1\n");
continue;
}
int ans=1;
for(int i = cnt-1;i>=1;i--){
if(w[i].num==w[i+1].num){
ans++;
}else break;
}
printf("%d\n",ans);
for(int i = cnt;i>cnt-ans;i--){
printf("%d ",b[w[i].id]);
}
printf("\n");
}
}

B

一道有趣的(并不)BFS

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
#include<cstdio>
#include<cstring>
using namespace std;
int fx[4]={0,0,1,-1};
int fy[4]={1,-1,0,0};
const int N=205;
struct xx{
int x,y;
}q[N*N];
char mp[N][N];
int vis[N][N];
int pre[N*N];
void check(int now){
while(now){
int t=pre[now];
int nx=q[t].x,ny=q[t].y;
int x=q[now].x,y=q[now].y;
if(nx==x&&y==ny+1) mp[nx][ny]='d';
if(nx==x&&y==ny-1) mp[nx][ny]='a';
if(x==nx+1&&y==ny) mp[nx][ny]='s';
if(x==nx-1&&y==ny) mp[nx][ny]='w';
now=t;
}
}

int main(){
int n,m,sx,sy,tx,ty;
scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&tx,&ty);
memset(vis,-1,sizeof(vis));
for(int i = 1;i<=n;i++){
scanf("%s",mp[i]+1);
for(int j =1;j<=m;j++) vis[i][j]=0;
}
int h,t;h=t=0;
q[++t].x=sx;
q[t].y=sy;
while(h<t){
int nowx=q[++h].x;
int nowy=q[h].y;
printf("%d %d\n",nowx,nowy);
if(nowx==tx&&nowy==ty){
check(h);
break;
}
if(mp[nowx][nowy]=='.'){
for(int i = 0;i<4;i++){
int newx=nowx+fx[i];
int newy=nowy+fy[i];
if(!vis[newx][newy]){
vis[newx][newy]=1;
pre[++t]=h;
q[t].x=newx;
q[t].y=newy;
}
}
}
if(mp[nowx][nowy]=='w'){
int newx=nowx-1;
int newy=nowy;
if(vis[newx][newy]==0){
vis[newx][newy]=1;
pre[++t]=h;
q[t].x=newx;
q[t].y=newy;
}
}
if(mp[nowx][nowy]=='s'){
int newx=nowx+1;
int newy=nowy;
if(vis[newx][newy]==0){
vis[newx][newy]=1;
pre[++t]=h;
q[t].x=newx;
q[t].y=newy;
}
}
if(mp[nowx][nowy]=='a'){
int newx=nowx;
int newy=nowy-1;
if(vis[newx][newy]==0){
vis[newx][newy]=1;
pre[++t]=h;
q[t].x=newx;
q[t].y=newy;
}
}
if(mp[nowx][nowy]=='d'){
int newx=nowx;
int newy=nowy+1;
if(vis[newx][newy]==0){
vis[newx][newy]=1;
pre[++t]=h;
q[t].x=newx;
q[t].y=newy;
}
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++) if(mp[i][j]=='.') mp[i][j]='a';
}
for(int i = 1;i<=n;i++){
printf("%s\n",mp[i]+1);
}
}

C

我还没写完qaq