当前位置:网站首页>Program design TIANTI race l2-007 family real estate (it's too against the sky. I always look at the solution of the problem, resulting in forgetting the problem and looking up how to write the collec
Program design TIANTI race l2-007 family real estate (it's too against the sky. I always look at the solution of the problem, resulting in forgetting the problem and looking up how to write the collec
2022-04-21 16:39:00 【Find a derivative first】
subject
The question : A little . Classical sorting problem .
Ideas : In a very stupid way , Drawing dfs Merge with union search set , Finally sort the output .
Time complexity : O( Yes )
Code :
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 9999;
int n,m,k,T;
struct node{
int id = 77777; // Number
int num = 1; // The number of
double tot; // The number of properties
double av; // Property area
bool operator<(const node&rhs)
{
if(av != rhs.av) return av > rhs.av;
return id < rhs.id;
}
}a[N];
vector<int> va[N];
int fa[N];
bool vis[N];
int find(int x)
{
return x==fa[x]?x:fa[x] = find(fa[x]);
}
bool Merge(int u,int v)
{
u = find(u),v = find(v);
if(u != v)
{
fa[v] = u;
return 1;
}
return 0;
}
void dfs(int st,int i)
{
for(int j:va[i])
{
// if(i==1) cout<<j<<"?\n";
if(Merge(st,j))
{
// a[st].id = min(a[i].id,j);
a[st].num += a[j].num;
a[st].tot += a[j].tot;
a[st].av += a[j].av;
dfs(st,j);
}
}
}
void solve()
{
for(int i=0;i<=M;++i) fa[i] = i;
cin>>n;
for(int i=0;i<n;++i)
{
int x,y,z;int num;
cin>>x>>y>>z>>num;
vis[x]=1;
if(y!=-1) va[x].push_back(y),va[y].push_back(x),vis[y]=1;
if(z!=-1) va[x].push_back(z),va[z].push_back(x),vis[z]=1;
while(num--)
{
int t; cin>>t;
vis[t] = 1;
va[x].push_back(t);
va[t].push_back(x);
}
cin>>a[x].tot>>a[x].av;
a[x].id = x;
}
for(int i=0;i<=9999;++i)
{
if(vis[i]&&find(i)==i)
{
a[i].id = i;
dfs(i,i);
}
}
vector<node> va;
for(int i=0;i<=M;++i)
{
if(vis[i] && find(i)==i)
{
a[i].av /= a[i].num;
a[i].tot /= a[i].num;
va.push_back(a[i]);
}
}
sort(va.begin(),va.end());
cout<<va.size()<<"\n";
for(int i=0;i<va.size();++i)
{
printf("%04d ",va[i].id);
cout<<va[i].num;
printf(" %.3lf %.3lf\n",va[i].tot,va[i].av);
}
}
signed main(void)
{
solve();
return 0;
}
版权声明
本文为[Find a derivative first]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211632354596.html
边栏推荐
- Want to make a fortune by "leaking data"? What a punishment
- Burp is a simple TP5 rce passive scanning plug-in
- Microsoft IE local file detection vulnerability
- Online dictionary website
- 程序设计天梯赛L2-007 家庭房产(太逆天了,做题老看题解导致忘了这题并查集怎么写了,直接建图dfs做的,麻烦的一)
- 云呐:机房资产管理系统web版,设备资产信息管理的应用
- 多核和多CPU編程——任務調度
- 手机硬件都有哪些
- Outsourcing student management system detailed architecture design document
- 遨游浏览器本地跨站脚本漏洞
猜你喜欢

Sort the exercises after class

【观察】紫光云:同构混合云升级为分布式云,让云和智能无处不在

云呐:资产密集型企业固定资产管理系统的基本功能特点

C语言程序的环境,编译+链接

Apache security configuration

服装行业要渡“疫情劫”,赢家时尚凭什么成为增长样本?

云呐:医院固定资产管理存在的问题及原因,资产管理系统的实施

If this question doesn't work, the interviewer will continue to ask me the JVM: how to judge whether an object is recyclable

Apache安全配置

SQL -- database operation (DDL, DML, DQL) + use the command to view the storage location of the current database (database version query)
随机推荐
手机硬件性能的发展主要受哪几方面制约
OJ daily practice - grade score
如果这题都不会面试官还会继续问我 JVM 嘛:如何判断对象是否可回收
SIGIR 2022 | reinforcement learning recommendation system from the perspective of prompt
IOS development interview strategy (KVO, KVC, multithreading, lock, runloop, timer)
SQL--数据库的操作(DDL,DML,DQL)+使用命令查看当前数据库的存储位置(数据库版本查询)
OJ每日一练——等级成绩
【观察】紫光云:同构混合云升级为分布式云,让云和智能无处不在
Are you sure you don't want to see it yet? Managing your code base in this way is both convenient and worry free
(11) definition of macro language - (C.4)
k线图看涨的13种形态(下)
目前5G SoC 芯片技术成熟吗?
OJ daily practice - integer in reverse order
OJ每日一练——最大公约数与最小公倍数
What are the mobile phone hardware
mingw下载
Inconsistent length of input and select in elmentui form
What are the mainstream types of mobile phone screens at present
The console displays VM + number + file name to debug
Mongodb security configuration