上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 182 下一页
摘要: 求欧拉回路。对全图进行dfs,从规定起点开始。过程中记录经过了哪些边,以保证每条边只经过一次。当一个点的所有边都遍历完成后,把该点入栈。最后依次弹栈得到的就是欧拉路径。被入栈的点都是走投无路的点,如果存在欧拉路径,第一次出现的走投无路一定是在走回到起点时,因为其他情况无论怎么走只可能略过一些边,而不可能走进死路。本题要把每条边加为双向边。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#def 阅读全文
posted @ 2011-09-06 08:36 undefined2024 阅读(452) 评论(0) 推荐(0)
摘要: 极坐标排序注意atan2(y,x)的使用方法,y在前,x在后。返回X轴正方向到原点到(x,y)点的射线的到角。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;#define maxn 55#define pi acos(-1)struct Point{ int x, y;} point[maxn]; 阅读全文
posted @ 2011-09-02 09:12 undefined2024 阅读(729) 评论(0) 推荐(0)
摘要: 快速幂View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define LL long longint m, h;LL power(LL a, LL b, LL m){ if (a == 0) return 0; if (b == 0) return 1; a %= m; LL x = a; LL ret = 1; for (; b > 0; b >>= 1, x = x * 阅读全文
posted @ 2011-09-01 16:06 undefined2024 阅读(273) 评论(0) 推荐(0)
摘要: 最短路View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define INF 0x3f3f3f3f#define N 105int path[N], vis[N];int cost[N][N];int lowcost[N];int n, a, b;void Dijkstra(int cost[][N], int lowcost[N], int n, int beg){ int i, j, mi 阅读全文
posted @ 2011-09-01 15:44 undefined2024 阅读(268) 评论(0) 推荐(0)
摘要: 题意:给定一个64位整数,问是否为质数,如果不是,则输出其最小因子。分析:经典题!!数学题miller_rabbin素数判定。若不是,则pollard_rho分解质因子,找到最小即可。Miller-rabinMiller-rabin算法是一个用来快速判断一个正整数是否为素数的算法。它利用了费马小定理,即:如果p是质数,且a,p互质,那么a^(p-1) mod p恒等于1。也就是对于所有小于p的正整数a来说都应该复合a^(p-1) mod p恒等于1。那么根据逆否命题,对于一个p,我们只要举出一个a(a#include #include #include #include constint S= 阅读全文
posted @ 2011-09-01 15:15 undefined2024 阅读(1895) 评论(0) 推荐(0)
上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 182 下一页