当前位置:网站首页>1107 social clusters (30 points)
1107 social clusters (30 points)
2022-06-30 14:54:00 【Xue Dongjing】
maxmin
1107 Social Clusters (30 branch )
The question
give n Personal interests , People with the same interests become a collection .
Number of output groups , Output the number of people in each group in descending order .
Ideas
Check your hobbies and , Open an array to record the number of people in each hobby . Finally, the number of all hobbies of a group is concentrated on the hobbies of the root node .
Code
// Begin to use map Storage , But found map It's not easy to use here , Something's wrong bug, On that basis .
#include<stdio.h>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
map<int,int>gp,pr;
map<int,int>::iterator itor;
map<int,int>::reverse_iterator to;
int pre[100007],ans[100007],ang[100007];
int find(int x)
{
int y=x,z;
while(x!=pre[x]){
x=pre[x];
}
while(y!=x){
z=pre[y];
pre[y]=x;
y=z;
}
return x;
}
void link(int a,int b)
{
pre[a]=b;
}
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,k,x,temp,p,q,cnt=0;
string str;
scanf("%d",&n);
for(int i=0;i<100007;i++){
pre[i]=i;
ans[i]=0;
}
for(int i=0;i<n;i++){
scanf("%d",&k);
cin>>str;
if(k!=0){
scanf("%d",&x);
p=find(x);
ans[p]+=1;
gp[p]=ans[p];
for(int j=1;j<k;j++){
scanf("%d",&x);
q=find(x);
if(p!=q){
link(q,p);
ans[p]+=ans[q];
gp[p]=ans[p];
ans[q]=0;
gp[q]=0;
}
}
}
}
for(itor=gp.begin();itor!=gp.end();itor++){
// Want to use map Automatic sorting of
// printf("!!!!%d %d\n",itor->first,itor->second);
if(itor->second!=0){
// printf("@@%d \n",itor->first);
// pr[itor->second]=itor->first;// When the two groups have the same number of people, there is a mistake here
ang[cnt++]=itor->second;
}
}
// printf("%d\n",pr.size());
sort(ang,ang+cnt,cmp);
printf("%d\n",cnt);
for(int i=0;i<cnt;i++){
if(i!=0){
printf(" ");
}
printf("%d",ang[i]);
}
// for(to=pr.rbegin();to!=pr.rend();to++){
// if(to!=pr.rbegin()){
// printf(" ");
// }
// cout<<to->first<<" "<<to->second<<endl;;
// }
return 0;
}
边栏推荐
- 文本匹配——【NAACL 2022】GPL
- Greedy two-dimensional array sorting
- Maximum area of islands searched
- Querywrapper in mybaits plus
- How to use Alibaba Vector Icon
- Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
- 先锋期货安全么?现在期货开户都是哪些流程?期货手续费怎么降低?
- Text matching - [naacl 2022] GPL
- [extensive reading of papers] a delicious recipe analysis framework for exploring multi modal recipes with variable attributes
- Invalid argument during startup: Failed to open the . conf file: redis-window
猜你喜欢
[email protected][])"/>NoViableAltException([email protected][])

val_ Loss decreases first and then increases or does not decrease but only increases

Thinkphp5 log file contains trick

【BUUCTF】 EasySql

DiceCTF - knock-knock

CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1

CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2

Shangpinhui knowledge points of large e-commerce projects

CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014

1 figure to explain the difference and connection between nodejs and JS
随机推荐
【BUUCTF】[GXYCTF2019]Ping Ping Ping1
[extensive reading of papers] analyzing connections between user attributes, images, and text
【BUUCTF】 EasySql
MV3 04_ Introducing Manifest V3
Basic learning notes of C language
Finding the root of an integer by dichotomy
1137: encrypted medical record
JS to realize simple lottery function
Sum of squares of two pointers
2021-08-05 leetcode notes
val_ Loss decreases first and then increases or does not decrease but only increases
Experiment 2: stack
Binary rotation array (2)
Att & CK red team evaluation field (I)
数控加工中心打刀缸工作原理及故障处理
2021-05-12
How to realize selective screen recording for EV screen recording
[extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
CCF date calculation (Full Score code + skill summary) February 2, 2015
Querywrapper in mybaits plus