poj2367】的更多相关文章

Genealogical tree poj-2367 题目大意:给你一个n个点关系网,求任意一个满足这个关系网的序列,使得前者是后者的上级. 注释:1<=n<=100. 想法:刚刚学习toposort,什么是toposort? 就是每一个点的遍历或选取有先决条件,那么我们可以通过队列或者栈将控制当前点的点先遍历,这样弹栈或出队的序列,就是toposort的结果 我们先附上模板 int v[100100];//入度 bool map[110][110]={false};//是否存在控制与被控制…
题意:有一些人他们关系非常复杂,一个人可能有很多后代,现在要制定一种顺序,按照前辈在后代前排列就行 拓扑序裸题,直接建边拓扑排序一下就行了. #include<stdio.h> #include<string.h> #include<queue> using namespace std; ][],id[],n; void topo(){ queue<int>q; ;i<=n;++i)if(!id[i])q.push(i); ; while(!q.emp…
裸拓扑排序. 拓扑排序 用一个队列实现,先把入度为0的点放入队列.然后考虑不断在图中删除队列中的点,每次删除一个点会产生一些新的入度为0的点.把这些点插入队列. 注意:有向无环图 g[] : g[i]表示从点i连出去的边 L[] :拓扑排序的结构 code: #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn = 100 + 5; vector…
Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4420   Accepted: 2933   Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. T…
很裸的拓扑排序~ //#include <bits/stdc++.h> #include<iostream> #include<string.h> #include<cstdio> #include<algorithm> using namespace std; typedef __int64 LL; const int N=1e2+10; int ma[N][N]; int pre[N]; int n; void tuopu() { int k…
/* author: keyboarder time : 2016-05-18 12:21:26 */ #include<cstdio> #include<string.h> #include<iostream> #define N 110 int pre[N]; int ma[N][N]; bool vis[N]; int n; void tuopu() { int cnt=0; memset(vis,0,sizeof(vis)); for(int i=1;i<…
http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <string> #include <queu…
思路: 拓扑排序,这里是用染色的dfs实现的.在有环的情况下可以判断出来,没有环的情况下输出拓扑排序序列. 实现: #include <vector> #include <cstring> #include <iostream> #include <algorithm> #define w 0 #define g 1 #define b 2 using namespace std; ; int G[N][N]; vector<int> res,…
#include<iostream> #include<vector> #include<queue> using namespace std; typedef long long ll; ; int in[N],n,r; vector<int>ans; vector<int>edge[N]; priority_queue<int,vector<int>,greater<int> >priq; int main…
---恢复内容开始--- Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4875   Accepted: 3236   Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where…
今天网易的笔试,妹的,算法题没能A掉,虽然按照思路写了出来,但是尼玛好歹给个测试用例的格式呀,吐槽一下网易的笔试出的太烂了. 就一道算法题,比较石子重量,个人以为解法应该是拓扑排序. 就去POJ找了道拓扑排序的题:POJ2367 直接上代码吧: #include<stdio.h> #include<string> #define clr(x) memset(x,0,sizeof(x)) ][]; ]; ]; using namespace std; int main() { int…
[POJ2367]Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5696   Accepted: 3729   Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where the…