解题思路:
设被怀疑的集合为a,b,c,d,e,已经确定的小球集合为f,那么最终答案为a^b^c^d^e - f。问题是怎样求交集,直接用一个map<int,int>记录某个小球被怀疑的次数,每读一次称重结果,对于怀疑的集合,遍历该集合,给其map值+1。对于确定的集合,遍历集合,插入到一个set中。读完以后,遍历set中的元素x,删掉其在map中的值,最终map中的最大值个数,就是答案。
注意事项:
参考代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e9+10;
map<int,int>s;
set<int> s2;
int n,m,b[1000010],c[1000010];
int main()
{
cin>>n>>m;
s.clear();
s2.clear();
int ans=0;
int ma=-1;
for(int i=1;i<=m;i++)
{
int cnt;
char res;
scanf(" %d",&cnt);
for(int j=1;j<=cnt;j++) scanf(" %d",&b[j]);
for(int j=1;j<=cnt;j++) scanf(" %d",&c[j]);
scanf(" %c",&res);
if(res=='<')
{
for(int j=1;j<=cnt;j++)
{
if(s2.find(c[j])==s2.end()) s2.insert(c[j]);
}
for(int j=1;j<=cnt;j++) {s[b[j]]++;ma=max(ma,s[b[j]]);}
}
else if(res=='>')
{
for(int j=1;j<=cnt;j++)
{
if(s2.find(b[j])==s2.end()) s2.insert(b[j]);
}
for(int j=1;j<=cnt;j++) {s[c[j]]++;ma=max(ma,s[c[j]]);}
}
else
{
for(int j=1;j<=cnt;j++)
{
if(s2.find(b[j])==s2.end()) {s2.insert(b[j]);}
if(s2.find(c[j])==s2.end()) {s2.insert(c[j]);}
}
}
}
set<int>::iterator it1;
for(it1=s2.begin();it1!=s2.end();it1++) s.erase(*it1);
map<int,int>::iterator it;
for(it=s.begin();it!=s.end();it++)
{
//printf("%d->%d\n",it->first,it->second);
if(it->second==ma) ans++;
}
if(ans!=0)
cout<<ans<<endl;
else
{
cout<<n-s2.size()<<endl;
}
return 0;
}
0.0分
2 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复