poj——2367 Genealogical tree
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6025 | Accepted: 3969 | Special Judge |
Description
And in the Planetary Council the confusing genealogical system leads to some embarrassment. There meet the worthiest of Martians, and therefore in order to offend nobody in all of the discussions it is used first to give the floor to the old Martians, than to the younger ones and only than to the most young childless assessors. However, the maintenance of this order really is not a trivial task. Not always Martian knows all of his parents (and there's nothing to tell about his grandparents!). But if by a mistake first speak a grandson and only than his young appearing great-grandfather, this is a real scandal.
Your task is to write a program, which would define once and for all, an order that would guarantee that every member of the Council takes the floor earlier than each of his descendants.
Input
Output
Sample Input
5 0 4 5 1 0 1 0 5 3 0 3 0
Sample Output
2 4 5 3 1 题目重现:
火星人血缘关系的制度令人困惑。实际上,火星人要发芽,想要什么。他们聚集在一起不同的群体,所以一个火星人可以有一个父母以及十个。没有人会惊讶于一百个孩子。火星人习惯了,他们的生活方式似乎是自然的。而在行星委员会,混乱的系谱系统会导致一些尴尬。遇到最有价值的火星人,所以为了在所有的讨论中冒犯任何人,首先要让老火星人,而不是对年轻人,而不是最年轻的无孩子的陪审员。然而,维护这个命令真的不是一件小事。不总是火星人知道他所有的父母(没有什么可以告诉他的祖父母!)。但是,如果一个错误首先说出一个孙子,而不是他的年轻人出现的爷爷,这是一个真正的丑闻。你的任务是编写一个程序,一劳永逸地定义一个可以保证安理会每一位成员比每个后裔早日发言的命令
思路:拓扑排序模板、、、
代码:
#include<queue> #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #define N 1010 using namespace std; queue<int>q; int n,m,s,tot,in[N],ans[N],head[N]; struct Edge { int to,next,from; }edge[N]; int add(int x,int y) { tot++; edge[tot].to=y; edge[tot].next=head[x]; head[x]=tot; } int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getchar();} return x*f; } int main() { n=read(); ;i<=n;i++) ) { m=read(); ) break; in[m]++;add(i,m); } ;i<=n;i++) ) q.push(i); while(!q.empty()) { m=q.front(),q.pop(); ans[++s]=m; for(int i=head[m];i;i=edge[i].next) { int t=edge[i].to; in[t]--; ) q.push(t); } } ;i<=s;i++) printf("%d ",ans[i]); ; }
poj——2367 Genealogical tree的更多相关文章
- POJ 2367:Genealogical tree(拓扑排序模板)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7285 Accepted: 4704 ...
- POJ 2367:Genealogical tree(拓扑排序)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2738 Accepted: 1838 Spe ...
- poj 2367 Genealogical tree
题目连接 http://poj.org/problem?id=2367 Genealogical tree Description The system of Martians' blood rela ...
- poj 2367 Genealogical tree【拓扑排序输出可行解】
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3674 Accepted: 2445 ...
- POJ 2367 Genealogical tree 拓扑排序入门题
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8003 Accepted: 5184 ...
- POJ 2367 Genealogical tree【拓扑排序/记录路径】
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7101 Accepted: 4585 Spe ...
- POJ 2367 topological_sort
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2920 Accepted: 1962 Spe ...
- timus 1022 Genealogical Tree(拓扑排序)
Genealogical Tree Time limit: 1.0 secondMemory limit: 64 MB Background The system of Martians’ blood ...
- Genealogical tree(拓扑结构+邻接表+优先队列)
Genealogical tree Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) ...
随机推荐
- AJPFX:关于面向对象及java的一些机制的思考
1.变量的作用域和生命周期什么关系? 2.java除了在类体和方法体(包括参数)中可以声明变量外,其他位置一定不可以声明变量吗?比如高级别的应用里是不是有例外呢? 3.java源文件中代码的组织方式一 ...
- Spring Mvc相关随笔
web.xml部分 1.欢迎界面 <welcome-file-list> <welcome-file>/views/login.jsp</welcome-file> ...
- c语言-依赖倒转
当一个文件(aa.c文件)依赖于头文件(bb.h)时,如果bb.c编译之后形成的bb.o文件重新编译后,aa.o的文件不需要重新编译 aa.c文件: bb.h文件:对bb.c文件进行声明 bb.c文件 ...
- rest_framework基于generics.CreateAPIView创建用户
最近在写新版的devops3.0,被generics.CreateAPIView创建用户密码序列化的问题折磨的欲仙欲死.反复看源码测试,得出下面的流程,这也是做generics.CreateAPIVi ...
- frame方式布局一段文子,设置宽高
计算一段文字的宽高 /** * 计算一段文字的宽高 * * @param size 这段文字的最大宽高 * @param options NSStringDrawingUsesLineFragment ...
- 《哈佛商业评论》2017年第5期:4星。成功CEO具有4种行为特质:果断、激励参与、主动适应、稳扎稳打。股东价值最大化的理念有重大缺陷。
老牌管理学杂志,每期都值得精度.本期几个比较重要的观点:谦逊的CEO能带来更好的业绩:飞利浦创新过度导致业绩下滑:股东最大化的理念有重大缺陷,后果之一是大宗股票的临时持有者可能干预公司事务,强迫公司采 ...
- 迅为I.MX6开发板工业级嵌入式开发平台
迅为-i.MX6开发板是是基于ARM Cortex™-A9架构的高扩展性多核系列应用处理器, i.MX6系列芯片而且根据应用场合的不同,提供了可供选择的单核.双核和四核产品供客户选择.i.MX6系列的 ...
- (转)SpringMVC学习(十一)——SpringMVC实现Resultful服务
http://blog.csdn.net/yerenyuan_pku/article/details/72514034 Restful就是一个资源定位及资源操作的风格,不是标准也不是协议,只是一种风格 ...
- 引用类型 (Reference Type Matters)、扩展与派发方式
引用类型 (Reference Type Matters) 引用的类型决定了派发的方式. 这很显而易见, 但也是决定性的差异. 一个比较常见的疑惑, 发生在一个协议拓展和类型拓展同时实现了同一个函数的 ...
- Mysql基本操作、C++Mysql简单应用、PythonMysql简单应用
MySql基本操作 -- 当指定名称的数据库不存在时创建它并且指定使用的字符集和排序方式 CREATE DATABASE IF NOT EXISTS db_name CHARACTER SET UTF ...