因为公用一个系统所以大家求gcd:衡量各点之间的拓扑位置,如果到达同一点有不同的长度则取gcd. #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 1e5 + 5; int n, m, ans; int val[maxn]; vector<int> adj[maxn],…
http://acm.hdu.edu.cn/showproblem.php?pid=5348 题意:给一个无向图,现在要将其变成有向图,使得每一个顶点的|出度-入度|<=1 思路:分为两步,(1)从图上找环,将环上边的方向设为一致,这样直到图中不存在环,最后剩下一个森林(2)对每一棵树的边进行编号,方法是从根节点向下,对每个点,将其与第一个儿子之间的边设置为与父亲之间的边“互补”的方向,而与儿子之间边的方向则交替分配,显然无论儿子多少个,这个点的出度与入度之差不会超过1.这样两步完成后,所有边都…
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2739 Time limit : 1 sec Memory limit : 64 M A Chinese postman is assigned to a small town in China to deliver letters. In this town, each street is oriented and connects exactly two junctions. The postma…
题目: You are given a binary tree with unique integer values on each node. However, the child pointers on each node may point to any other node in the tree including itself, introducing cycles into the binary tree. A cycle is defined when you can trave…
问题的提法是:给定一个没有负权值的有向图和其中一个点src作为源点(source),求从点src到其余个点的最短路径及路径长度.求解该问题的算法一般为Dijkstra算法. 假设图顶点个数为n,则针对其余n-1个点需要分别找出点src到这n-1个点的最短路径.Dijkstra算法的思想是贪心法,先找出最短的那条路径,其次找到次短的,再找到第三短的,依次类推,直到找完点src到达其余所有点的最短路径.下面举例说明算法和贪心过程. 如下图所示(该图源自<数据结构预(用面向对象方法与C++语言描述)(…
题意: 以每个点为起点,找到第一个出现两次的点 解析: 我是先找出来所有的环  环上的点找出来的肯定是自己 bz[i]  = i; 然后去遍历不在环上的点j  如果通过这个点找到一个已经标记的的点i  那么bz[j] = bz[i]; 行吧...其实直接暴力 就几行代码...真是的...过分....我真是垃圾啊..啦啦啦...呸.. #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffff; vector<int&g…
codeforces 897B Chtholly's request 题目链接: http://codeforces.com/problemset/problem/897/B 思路: 暴力求出这100000个偶数回文数,说是暴力,其实是直接求出,O(n).然后累加求和取模即可.注意WA test 12是因为没有求导最后一个回文数,心痛啊,调了一个半小时最后没检查出来,一定要注意范围 代码: #include <iostream> #include <algorithm> #incl…
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station …
逗号空格是假的,全都直接连边就行. 提供一个迪杰n次的图上最小环板子. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; const int maxn = 505; const…
Android中获取字符串长度.宽度(所占像素宽度) 计算出当前绘制出来的字符串有多宽,可以这么来! 方法1: Paint paint = new Paint(); Rect rect = new Rect(); //返回包围整个字符串的最小的一个Rect区域 paint.getTextBounds(text, 0, 1, rect); strwid = rect.width(); strhei = rect.height(); 方法2: //直接返回参数字符串所占用的宽度 strWidth =…