摘要: 今天做面试题,有一个文件上传的,发觉以前做项目为了赶时间都是直接用别人的上传类,交笔试题,怎么也不能用别人的吧,所以就写了一个,可能很多bug,没实际项目测试过,呵呵
<?php/** * 文件上传类 * 成员变量带*号必须要初始化 * @version 1.0 * @author howe...
阅读全文
posted @
2008-04-12 11:47 豪 阅读(1509) |
评论 (0) |
编辑 收藏
摘要: 发觉计算机很多东西都是相同的,记得操作系统时候学过这一概率 copy on write,在Reference Counted中彻底用到,代码的设计确实精妙,可以在不修改客户端得类,利用RCIPtr间接指针,对客户端的类实现引用计数,太妙了,详细见代码吧,代码中Widget为已有的客户端的类,RCIPtr是一个间接指针,RCObject是引用计数的基类,所有需要引用计数的类都必须继承他,换句话说,R...
阅读全文
posted @
2008-04-09 21:36 豪 阅读(537) |
评论 (0) |
编辑 收藏
The Strategy Pattern
Defines a family of algorithms, encapsulates each one, and makes them interchangeable.
Strategy lets the algorithm vary independently from clients that use it.
Observer Pattern
Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Decorator Pattern
Attach additional responsibilities to an object dynamically.
Decorators provide a flexible alternative to subclassing for extending functionality.
Factory Pattern
Abstract Factory
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Factory Method
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Factory Pattern lets a class defer instantiation to the subclasses.
Singleton
Ensure a class only has one instance and provide a global point of access to it.
The Command Pattern
encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.
The adapter pattern
Adapter Converts the interface of a class into aniother interface clients expect. Lets classes work together that couldnt otherwise because of incompatible interfaces.
Facade Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
posted @
2007-11-22 12:26 豪 阅读(303) |
评论 (0) |
编辑 收藏
原来用stl的优先队列这么爽,比赛时候多用,heap太容易打错了,毕竟没ghost_wei那么bt(heap,就几行,都打烂了-_-)
pku3159:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1 << 28;
const int MAXN = 30010;
struct PQNode {
int u, key;
//pq默认用<判断优先级,key大优先,若要key小优先,则加上!或<改成>即可
friend bool operator<(const PQNode &a, const PQNode &b) { return !(a.key < b.key); }
};
int n, m;
vector<int> adjv[MAXN], adjw[MAXN];
int dijkstraPQ(int st, int en) {
int i, v, w, dist[MAXN], chk[MAXN];
priority_queue<PQNode> pq;
PQNode tmp, cp;
memset(chk, 0, sizeof(chk));
for (i=0; i<n; i++) dist[i] = INF;
dist[st] = 0;
tmp.u = st; tmp.key = 0;
pq.push(tmp);
while (!pq.empty()) {
cp = pq.top();
pq.pop();
if (cp.u == en) return dist[en];
if (chk[cp.u]) continue;
chk[cp.u] = 1;
for (i=0; i<adjv[cp.u].size(); i++) {
v = adjv[cp.u][i]; w = adjw[cp.u][i];
if (!chk[v] && (dist[v]==INF || dist[v]>cp.key+w)) {
dist[v] = cp.key+w;
tmp.u = v; tmp.key = dist[v];
pq.push(tmp);
}
}
}
return -1;
}
int main() {
int i, j, k, u, v, w;
freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &m);
for (i=0; i<m; i++) {
scanf("%d%d%d", &u, &v, &w);
u--; v--;
adjv[u].push_back(v);
adjw[u].push_back(w);
}
printf("%d\n", dijkstraPQ(0, n-1));
return 0;
}
posted @
2007-11-03 16:40 豪 阅读(1314) |
评论 (4) |
编辑 收藏
摘要: 该算法有几个可学习的地方:(1)正负1思想(2)对边界条件的处理(3)数据结构的选择code:sweep.h
#ifndef SWEEP_H#define SWEEP_Hstruct Edge { int nxty; int curx; ...
阅读全文
posted @
2007-10-20 22:33 豪 阅读(7785) |
评论 (3) |
编辑 收藏