- 博客(9)
- 收藏
- 关注
原创 拓扑排序
int indegree[100]; queue<int> q; int n,m; bool map[100][100]; int a[100]; int topo(int n) { int cnt = 1; while(!q.empty()) q.pop(); for(int i = 1; i <= n ; i++) if...
2018-05-24 18:17:43 331
原创 青蛙的约会(poj 1061)
青蛙的约会假设:跳x1次后相遇,相遇时路乘差是y1*l(跳了y1圈)列出方程:x+m*x1-(y+n*x1)=y1*l ;化简为(n-m)*x1+y1*l=x-y ;代码:#include<iostream> #include<cstdio> using namespace std; long long exgcd(long long a,long long b,lon...
2018-05-16 17:30:18 863
原创 Romantic(hdu 2669)
Romantic扩展欧几里德算法。先用扩展欧几里德算法求出x,y然后再判断x是否大于0,如果小于0,则通过循环+b,直到x>0,在输出答案.代码:#include<iostream> #include<cstdio> using namespace std; long long exgcd(long long a,long long b,long long&...
2018-05-16 15:50:08 250
原创 欧拉路,回路
判定: 欧拉路: 有向图:图连通,有一点入度>出度,有一点出度>入度,其余点入度=出度或入度=出度;Play on Words 无向图:图连通,零个或两个奇数度,其余偶数度;一笔画问题 欧拉回路: 有向图:图连通,入度=出度; 无向图:图连通,零个奇数度;John's trip ...
2018-05-16 15:42:15 158
原创 Watchcow(poj 2230)
Watchcow求无向图每条边恰好经过两次,在回到原点,输出经过的顶点。容易转化为有向图欧拉回路每条边经过一次。代码:#include <stdio.h> #include <stack> #include <vector> #include <iostream> using namespace std; #define M 100005 str...
2018-05-15 22:16:03 544 2
原创 John's trip(poj 1041)
John's trip题目大意: 给出无向图,每条边有唯一的序号,是否存在欧拉回路,若存在输出边序号最小字典序的路径。下面代码没有判断图连通,根据题意图应该联通了,只需判断零个奇数点就可以了。代码:#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>...
2018-05-15 21:16:54 209
原创 Play on Words
Play on Words题意就是给你n个由小写字母构成的字符串,问你能不能将这n个字符串连接起来,B能接在A后面的条件是A的最后一个字母==B的第一个字母。然后就是将26个小写字母看成顶点集,对于一个字符串,其首字母向尾字母连一条单向边构图,所以本题就是有向图的欧拉路问题。代码:#include<cstdio> #include<vector> #include<c...
2018-05-15 20:22:58 167
原创 Ant Trip(HDU 3018)
Ant Trip一笔画问题,无向图欧拉路或者欧拉回路,注意题目说了,如果是孤立点,则不用考虑。对于每个连通块,如果全都是偶数度(欧拉回路),则需要1笔;如果不是,则需要奇数度顶点个数的1/2笔。代码:#include<bits/stdc++.h> using namespace std; int par[100005]; struct node { int du...
2018-05-15 12:27:20 196
原创 一笔画问题(nyoj 42)
一笔画问题对于无向图G,具有一条欧拉路(一笔画),当且仅当G是连通的,且有零个或两个奇数度结点。代码:#include<bits/stdc++.h> using namespace std; int par[1001]; int G[1001]; void init(int n) { for(int i=1;i<=n;i++) ...
2018-05-15 10:51:55 322
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人