模板
文章平均质量分 64
ygqwan
这个作者很懒,什么都没留下…
展开
-
求因子
#include#includeusing namespace std;int wan[1000];int yinzi(int m){ int i,v=0; int fang=sqrt(m); for(i=1;i<=fang;i++) if(m%i==0) { wan[v]=i; v+原创 2012-10-30 01:33:15 · 722 阅读 · 0 评论 -
有向图的DFS遍历及判断是否有环(算法导论)
#include #include #include #include #include #include using namespace std;const int MAX = 1000;int color[MAX];int Time;bool is_DAG; // 分别是时间撮,是否有环int first[MAX],last[MAX]; // 最先被访问的时间撮,原创 2013-04-29 14:14:08 · 8567 阅读 · 4 评论 -
最大流模板
Edmods_Karp 算法时间复杂度: O(n * m * m)//EK#include #include #include #include #define CLR(arr, v) memset(arr, v, sizeof(arr))#pragma warning (disable:4996)using namespace std;const int MaxE原创 2013-09-25 08:54:58 · 768 阅读 · 0 评论 -
vector存图
用vector存图并执行相关操作#include #include #include #include #include #include #include #define print(a) cout << #a << " : " << a << endlusing namespace std;struct node{ int v; int w; no原创 2013-09-18 17:17:49 · 2337 阅读 · 1 评论 -
Hdu 4768 Flyer(2013长春网络赛)
不断的异或就可以了, 用了一个等差数列连续异或的模板#include typedef __int64 LL;#include using namespace std;LL Get(LL a,LL b,LL c,LL n) { LL res=0; res+=(b/c)*n;b%=c; res+=(a/c)*n*(n-1)/2;a%=c; if (a*n+b<c)原创 2013-09-28 18:40:10 · 1104 阅读 · 0 评论 -
hdu4720 三角形的最小圆覆盖
求一个三角形的最小圆覆盖两种情况:1. 是锐角及直角三角形, 那么这个圆就是外接圆2. 是钝角三角形, 那么这个圆的直径是这个最长边的中点double getDis(Point a, Point b){ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}//////////////原创 2013-09-11 19:47:41 · 2590 阅读 · 0 评论 -
最小圆覆盖
代码如下:#include #include #include using namespace std;const int N = 1005;struct node{ double x, y;}p[N];node center; //圆心 double radius; //半径double dis(node s, node t){ ret转载 2013-09-11 20:12:34 · 803 阅读 · 0 评论 -
Topplogical-Sort
Topological Sort程度★ 难度★★楔子在枚举所有排列的问题之中,如果我们另外再限制谁要排在谁前方、谁要排在谁后方,那么在这些限制之下,合理的排列还会剩下哪些呢?【注:枚举所有排列,读者们可另行参考「Enumerate all n-tuples」一文。】先后限制与图谁要排在谁前方、谁要排在谁后方,其实就是两两之间的关系,故可以改用图来表示转载 2013-04-27 19:59:47 · 869 阅读 · 0 评论 -
判断两个数是否为素数的递归法
bool a_b_prime(int u,int v){ int c; while(v) { c=u%v; u=v; v=c; } if(u==1) return true; return false;}int prime(int a, int b) //网上发现的递归{ return (b == 0)? (a == 1) : prime(b, a % b原创 2013-03-26 19:33:44 · 1973 阅读 · 2 评论 -
线段树模板
#include #include #include using namespace std;const int SIZE = 10010;struct node // the node of line tree{ int i,j; // 区间范围 node * lson; node * rson; int count; // 线段覆盖条数转载 2013-03-30 16:39:33 · 773 阅读 · 0 评论 -
次方求模
long long mod(long long a,long long b,long long c){ long long t; if(b==0) return 1; else if(b==1) return a%c; else { t=mod(a,b>>1,c); t=t*t%c; if(b&1) t=t*a%c; } return t;}原创 2012-09-13 10:30:40 · 527 阅读 · 0 评论 -
邻接表与逆邻接表(数组实现)
引用头文件:string.h使用宏定义:#define CLR(arr,val) memset(arr,val,sizeof(arr))使用说明:每次使用前必须要先调用Init()函数,AddEdge()用来加边。#include #include #include #include #include #include using namespace std;con原创 2013-05-10 09:41:19 · 6263 阅读 · 0 评论