20210114-Virtual Judge A - Andryusha and Socks 题解
作者:互联网
20210114-Virtual Judge A - Andryusha and Socks
A - Andryusha and Socks <------原题在这!
题目大意
Andryusha有 n双袜子,她从袋子中一只一只将袜子拿出,如果有袜子成双,则将袜子放进wardrobe。若無,则放到桌子上。
问:桌子上最多会有多少只袜子?
解析
只要把每只袜子对应的序号出现的次数存入数组中,判断是0或1即可。
代码
#include <bits/stdc++.h>
const int N = 1e5+10;
using namespace std;
int main(){
int n,a,b[2*N],num = 0,maxn = 0;
memset(b,0,sizeof(b)); //记得初始化为0
cin >> n;
for(int i = 0;i < 2*n;i++){
cin >> a;
if(b[a] == 1) num--;
if(b[a] == 0){
num++;
b[a]++;
}
maxn = max(num,maxn);
}
cout << maxn << endl;
return 0;
}
END
标签:袜子,int,题解,Socks,num,Andryusha,maxn 来源: https://blog.csdn.net/Is_TuTouYa/article/details/112628401