2015年4月12日

sdut Thrall’s Dream(判断任意两点是否联通)

摘要: 题意:给一张无向图,判断任意两点是否联通;思路:bfs枚举个点,逐个遍历;#include#include#include#include#includeusing namespace std;int con[2005][2005];vector v[2005];int n,m;int judge(... 阅读全文

posted @ 2015-04-12 10:22 大树置林 阅读(424) 评论(0) 推荐(0) 编辑

hdu 3635 Dragon Balls(并查集技巧)

摘要: 题意:n个点m次询问,两种操作:1.将含有龙珠i的集合加入含有龙珠j的集合中;2.查询龙珠i所在堆的编号,龙珠个数,龙珠i的搬运次数;思路:并查集,数组分别维护关系、数量、搬运次数;#include#include#includeusing namespace std;int n,m;int fa[... 阅读全文

posted @ 2015-04-12 01:12 大树置林 阅读(154) 评论(0) 推荐(0) 编辑

2015年4月11日

hdu 1598 find the most comfortable road

摘要: 题意:给出一幅无向图,每次询问给出起点和终点,求起点到终点权值差最小的一条路,输出权值差;思路:边按权值排序,利用并查集枚举每次能使起点终点联通的情况下权值差,并每次更新最小值;#include#include#includeusing namespace std;#define INF 0x3f3... 阅读全文

posted @ 2015-04-11 19:38 大树置林 阅读(115) 评论(0) 推荐(0) 编辑

2015年4月10日

HDU 1272 小希的迷宫 (无向图判环)

摘要: 题意:给出一张无向图,判定是否有环,判定是否为一棵树;思路:并查集判环,唯一祖先;#include#include#includeusing namespace std;#define M 0x3f3f3f3fint fa[500010],mark[500010];void init(){ f... 阅读全文

posted @ 2015-04-10 20:09 大树置林 阅读(138) 评论(0) 推荐(0) 编辑

2015年4月7日

UVA 583 素数打表(线性)

摘要: 题意:将一个给定的数分解为素数乘积的形式输出;思路:先预处理出素数,再分解,格式模拟上需要花点时间调;#include#include#include#includeusing namespace std;int num[5000100],v[5000100];int su[5000100],shu... 阅读全文

posted @ 2015-04-07 17:47 大树置林 阅读(206) 评论(0) 推荐(0) 编辑

2015年4月5日

uva 11827 Maximum GCD(输入技巧)

摘要: 题意:对于给定的一组数,求该组数中两两gcd的最大值;思路:简单gcd,亮点在于每组数的个数并不提供,因此需要在读入是做出判断;#include#include#include#includeusing namespace std;#define eps 1e-5int t,i,j,k,num[50... 阅读全文

posted @ 2015-04-05 11:38 大树置林 阅读(262) 评论(0) 推荐(0) 编辑

2015年4月4日

hdu 1757 A Simple Math Problem 构造矩阵

摘要: 题意:函数f(x), 若x = 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); 且 ai(0#include#includeusing namespace std;typedef struct ... 阅读全文

posted @ 2015-04-04 20:28 大树置林 阅读(141) 评论(0) 推荐(0) 编辑

poj 1995 Raising Modulo Numbers 二分快速幂

摘要: 题意:给定n对Ai,Bi,求所有Ai的Bi次方之和对M取模的结果;思路:二分法求快速幂;#include#include#includeusing namespace std;__int64 sum,x,y,t;__int64 mod(__int64 a,__int64 b,__int64 c){ ... 阅读全文

posted @ 2015-04-04 17:40 大树置林 阅读(137) 评论(0) 推荐(0) 编辑

poj 1006 Biorhythms 中国剩余定理

摘要: 题意:求数n,使(n+d)%23==p,(n+d)%28==e,(n+d)%33=i;转载请注明出处:http://www.cnblogs.com/dashuzhilin/;思路:中国剩余定理。利用同余的加性,将(n+d)拆成三个数a,b,c, 使a%23==p,a%28==0,a%33==0... 阅读全文

posted @ 2015-04-04 16:51 大树置林 阅读(385) 评论(0) 推荐(0) 编辑

poj Matrix Power Series 矩阵幂求和

摘要: 题意:给一个n*n的矩阵A,求k次幂之和S=A+A2+A3+ … +Ak思路:矩阵快速幂。#include#include#includeusing namespace std;typedef struct node{ int matrix[55][55];}Matrix;Matrix a,s... 阅读全文

posted @ 2015-04-04 11:42 大树置林 阅读(228) 评论(0) 推荐(0) 编辑

2015年3月29日

poj 3083 dfs+bfs

摘要: 题意:给一张地图,分别求向左优先、向右优先、最短路三种走法从起点到终点的步数;思路:向左向右采用dfs,最短路采用bfs;#include#include#includeusing namespace std;char mm[550][505],flag;int n,m,s1,s2,e1,e2,i,... 阅读全文

posted @ 2015-03-29 19:51 大树置林 阅读(216) 评论(0) 推荐(0) 编辑

导航