当前位置:网站首页>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;
}
边栏推荐
- val_ Loss decreases first and then increases or does not decrease but only increases
- Error $(...) size is not a function
- Knowledge learned from the water resources institute project
- [extensive reading of papers] multimodal joint attribute prediction and value extraction for e-commerce product
- How to realize selective screen recording for EV screen recording
- CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014
- Distributed -- openresty+lua+redis
- IO interview questions
- Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
- 2021-07-14 mybaitsplus
猜你喜欢

@PathVariable

DefCamp Capture the Flag (D-CTF) 2021-22 web
![[buuctf] [geek challenge 2019] secret file](/img/00/23bebd013eb4035555c0057725e3c4.jpg)
[buuctf] [geek challenge 2019] secret file

1 figure to explain the difference and connection between nodejs and JS

The first dark spring cup dnuictf

CCF access control system (Full Score code + problem solving idea) 201412-1

Computer screenshot how to cut the mouse in

Clear the route cache in Vue

2021-07-14 mybaitsplus

CCF window (Full Score code + problem solving idea) March 2, 2014
随机推荐
1135: paired base chain
ThinkPHP show method parameter controllable command execution
MV3 04_ Introducing Manifest V3
1137: encrypted medical record
Double pointer letter matching
August 24, 2021 deque queue and stack
Pseudocode writing specification
高精度CNC加工中心为什么会出现误差?这4个原因你要注意!
先锋期货安全么?现在期货开户都是哪些流程?期货手续费怎么降低?
1 figure to explain the difference and connection between nodejs and JS
KnightCTF WEB
V3 03_ Getting started
CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014
HD mechanical principle · classic dynamic drawing of mechanical design
DiceCTF - knock-knock
Maximum area of islands searched
Experiment 2: stack
Vue returns to the previous page without refreshing the page / Vue caches the page
Introduction to the construction and development of composer private warehouse
Analysis on the problems of irregular step hole on horizontal machining center