摘要:
/*
Floyd的应用
用Floyd求出任意两点间的最短路径
两个定理:
1.所求的路径一定是一断连续的路径
2.如果路径(x,y)是a->b的最短路径中的一段,则min(a,b) = min(a,x) + min(x,y) + min(y,b)
最后只需找到同时在两条最短路径上,且距离最长的那一段
*/
#include <iostream>
using namespace std; const int inf=200000000; int s[305][305];//记录最短路的长度
int num[305][305];//同样长度的最短路的最长的跳数 int main( 阅读全文
posted @ 2011-12-31 14:57
windmissing
阅读(164)
评论(0)
推荐(0)
摘要:
/*
Floyd.h
时间复杂库:O(N^3)
用途:
1.判断中否联通
s[a][b] != inf -> 联通
s[a][b] == inf -> 不联通
2.两点间最短路径长度
s[a][b] != inf -> 最短路径长度 = s[a][b]
s[a][b] == inf -> 不联通
3.两点间的最短路径的跳数
初始化时所有路径长度设为单位长度
s[a][b] != inf -> 跳数 = s[a][b]
s[a][b] == inf -> 不联通
*/
#include <iostream> using namespace std; 阅读全文
posted @ 2011-12-31 14:41
windmissing
阅读(219)
评论(0)
推荐(0)
摘要:
//数据结构-栈的应用
#include<iostream>
#include<string>
#include<vector>
using namespace std; struct node
{ int value;//值 int add;//+的次数
};
//用容器实现栈的FILO
vector<node> ans;//数值栈
vector<char> sig;//符号栈
int main()
{ int t, i; string str; node temp, temp2; cin>>t; while(t--) 阅读全文
posted @ 2011-12-31 14:00
windmissing
阅读(129)
评论(0)
推荐(0)
摘要:
HDU1254 推箱子 BFS+优先队列HDU2433 Travel BFS求最短路径树+优化HDU1401 Solitaire 双向搜索 阅读全文
posted @ 2011-12-31 13:41
windmissing
阅读(121)
评论(0)
推荐(0)
摘要:
/*
箱子和人共同组成一个状态,用node来记录状态
使用优先队列,是因为只有箱子移动,记数才+1,并不是每次都+1,
从队列中选择记数最小的,进行下一步搜索
只使用优先队列不能保证结果是最小。
因为两个记数相同的状态,下一步的记数不一定相同
使用flag避免重复计算
*/
#include <iostream>
#include <queue>
using namespace std; struct node
{ int ceil; int people_x,people_y; int box_x,box_y; bool operator<(const node 阅读全文
posted @ 2011-12-31 13:41
windmissing
阅读(166)
评论(0)
推荐(0)
摘要:
1.Fibonacci Number0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377, 610 …Formula:2.Lucas Number1, 3, 4, 7, 11, 18, 29, 47, 76, 123...Formula:3.Catalan Number1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786,208012…Formula:Application:1) 将 n + 2 边形沿弦切割成 n个三角形的不同切割数2) n + 1个数相乘, 给每两个元素加上括号的不同方法 阅读全文
posted @ 2011-12-31 13:04
windmissing
阅读(221)
评论(0)
推荐(0)
摘要:
/*
还是暴力打表,然后规律
递推公式:
a[n]=4*a[n-1]+5(n为奇数)
a[n]=4*a[n-2]+5(n为偶数)
结果:
ans=2*4^n-5*(4^n-1)/3(n为奇数)
ans=2*4^n-4*(4^n-1)/3(n为偶数)
这里由于涉及到除法取余,所以还要把3的逆元求出来
*/
#include<stdio.h> #include<stdlib.h> #define mod 10007 //非递归方法求p^b
__int64 power(__int64 p,__int64 b) { __int64 sq=1; while(b... 阅读全文
posted @ 2011-12-31 13:03
windmissing
阅读(175)
评论(0)
推荐(0)

浙公网安备 33010602011771号