http://acm.timus.ru/problem.aspx?space=1&num=1392

一个森林   每棵树上的节点为一组  然后按照每种顺序输出

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#define LL long long
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;const int N=1005;
const int INF=0x3f3f3f3f;
//typedef pair<int,int>point;
int head[N],I;
struct node
{int j,next;
}side[N*N*2];
struct point
{int x,y,z;int r;
}mem[N];
vector<int>vt[N];
bool visited[N];
void add(int i,int j)
{side[I].j=j;side[I].next=head[i];head[i]=I++;
}bool Reachable(int i,int j)
{return sqrt(1.0*(mem[i].x-mem[j].x)*(mem[i].x-mem[j].x)+(mem[i].y-mem[j].y)*(mem[i].y-mem[j].y)+(mem[i].z-mem[j].z)*(mem[i].z-mem[j].z))<double(mem[i].r+mem[j].r);/*int d=0,sum=0;if(mem[i].x!=mem[j].x){++sum;d=abs(mem[i].x-mem[j].x);}if(mem[i].y!=mem[j].y){++sum;d=abs(mem[i].y-mem[j].y);}if(mem[i].z!=mem[j].z){++sum;d=abs(mem[i].z-mem[j].z);}if(sum>1)return false;if(d>=mem[i].r+mem[j].r)return false;return true;*/
}void Init(int n)
{for(int i=0;i<n;++i){scanf("%d %d %d %d",&mem[i].x,&mem[i].y,&mem[i].z,&mem[i].r);for(int j=0;j<i;++j){if(Reachable(i,j)){add(i,j);add(j,i);}}}
}
void dfs(int x,int k)
{visited[x]=true;vt[k].push_back(x);for(int t=head[x];t!=-1;t=side[t].next){int j=side[t].j;if(!visited[j]){dfs(j,k);}}
}
int main()
{//freopen("data.in","r",stdin);int n;while(scanf("%d",&n)!=EOF){memset(head,-1,sizeof(head));I=0;Init(n);memset(visited,false,sizeof(visited));for(int i=0;i<n;++i)vt[i].clear();int m=0;for(int i=0;i<n;++i)if(!visited[i])dfs(i,m++);for(int i=0;i<m;++i){sort(vt[i].begin(),vt[i].end());for(unsigned int j=0;j<vt[i].size();++j){if(j>0)cout<<", ";cout<<vt[i][j];}cout<<endl;}}
}

  

转载于:https://www.cnblogs.com/liulangye/archive/2013/01/18/2866843.html

1392. Dreaming of Stars相关推荐

  1. Codeforces 997 C - Sky Full of Stars

    C - Sky Full of Stars 思路: 容斥原理 题解:http://codeforces.com/blog/entry/60357 注意当i > 1 且 j > 1,是同一种 ...

  2. poj 2352 Stars 线段树(先建后查/边建边查)/树状数组三种方法思路详解,带你深入了解线段树难度⭐⭐⭐★

    poj 2352 Stars 目录 poj 2352 Stars 1.树状数组 2.线段树,先建树后查找 3.线段树,边建树边查找 Description Astronomers often exam ...

  3. California Dreaming

    约翰.菲力普斯原是一支名叫"行者"(Journeyman)的民歌合唱组的成员.一次他去旧金山的一个酒吧演出时,台下一个才十六岁的漂亮的女中学生被这个身材瘦高(他有一米九十多),充满 ...

  4. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  5. POJ 2481 Cows POJ 2352 Stars(树状数组妙用)

    题目链接:POJ 2481 Cows POJ 2352 Stars 发现这两个题目都跟求逆序数有着异曲同工之妙,通过向树状数组中插入点的位置,赋值为1,或者++,然后通过求和来判断比当前 点 &quo ...

  6. 搜索github项目stars排名

    搜索github项目stars排名 文章目录: 一.介绍 二.使用实例 1.996.ICU 2.搜索我想要某方向的优质项目 一.介绍 有时我们会想搜索一些比较好的项目,虽然stars多的不一定是非常好 ...

  7. POJ 2352 Stars (线段树)

    POJ 2352 Stars (线段树) 手动博客搬家:本文发表于20170819 22:11:49, 原地址https://blog.csdn.net/suncongbo/article/detai ...

  8. 2021HDU多校8 - 7059 Counting Stars(线段树)

    题目链接:点击查看 题目大意:给出 nnn 个数字,需要执行 mmm 次操作,每次操作分为下列三种类型: 1 l r :输出区间 [l,r][l,r][l,r] 的 sumsumsum 和 2 l r ...

  9. POJ2352 stars(树状数组)

    题目:Stars #include <stdio.h> #include <string.h> const int N = 32005; int C[N]; int level ...

最新文章

  1. 【交换机】交换机如何配置光电复用接口
  2. 被围绕的区域(dfs)
  3. VS2010+WinXP+MFC程序 无法定位程序输入点于动态链接库
  4. c++的thread类(c++线程简单用法)
  5. Python高级——with上下文管理器
  6. Mongodb 备份 还原 导出 导入 等批量操作
  7. CYQ.Data 数据框架 加快开源速度 发布V1.5.5版本源码
  8. 如何建立MFC绘图工程:外貌框架_基于对话框(开发平台VS2017)
  9. getAttribute, getParamter区别 转帖
  10. paip.函数式编程方法概述以及总结
  11. Intel Visual Fortan与gfortran使用rename函数的区别
  12. 秦纪三 二世皇帝下二年(癸已、前208)——摘要
  13. 怎么在计算机上搭建远程桌面,创建远程桌面连接的方法
  14. 微信小程序小说搭建流程
  15. 19年全国电赛 H题电磁炮硬件电路+可控硅
  16. 明日之后最新服务器开服时间,明日之后新区开服时间 新区开放表[图]
  17. uniapp 实现登录功能与获取用户凭证
  18. Mysql数据库和数据表的创建和信息更改的常用指令
  19. 微信公众号如何无限制的定向推送消息--模板消息的应用
  20. 企业级Docker虚拟化平台实战

热门文章

  1. DevTools failed to load source map: Could not load content for…System error: net::ERR_FILE_NOT_FOUN
  2. 人到了中年在职场中就应该保持内敛的心态
  3. 5G网络出来以后,家里面的宽带还有存在的必要吗?
  4. ios13.4.1续航怎么样?
  5. 网恋奔现发现对方长得很好看是什么样的体验?
  6. 很多家长学历不高,无法辅导孩子的家庭作业怎么办?
  7. 最近在学习文案,一边看文案书,一边勾画笔记,一边练习
  8. 企业不同时期该如何做股权布局?
  9. 经常有职场上的朋友问我,要怎么去轻资产创业?
  10. 厂商为什么不能用前一代的处理器库存做一个便宜的笔记本电脑?