摘要: 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2849题意:给定当前网络的病毒感染状态,求最终各编号病毒所能感染的电脑数。给定一张N*M大小的地图(N,M=0时该电脑才能被感染。3、编号小的病毒优先行动,只有低编号... 阅读全文
posted @ 2016-01-25 14:48 蓦辰 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Graham算法平均复杂度:N log(N)#include #include #include #include #include using namespace std;const int Max = 1100;#define PI 3.1415926struct Point{ int x... 阅读全文
posted @ 2016-01-25 12:48 蓦辰 阅读(149) 评论(0) 推荐(0) 编辑
摘要: /*题意:给定N个D维坐标。求最远曼哈顿距离。解法:对于两个二维坐标A(xi,yi),B(xj,yj).其曼哈顿距离可能为以下四种情况:(xi-xj)+(yi-yj), (xj-xi)+(yi-yj), (xi-xj)+(yj-yi), (xj-xi)+(yj-yi)将坐标参数按点来分配之后变形如下... 阅读全文
posted @ 2016-01-25 11:12 蓦辰 阅读(1177) 评论(0) 推荐(0) 编辑
摘要: /*BFS:多类单个门,配多把钥匙*/#include #include #include #include #include #include #include #include #include #include using namespace std;#includeconst int INF... 阅读全文
posted @ 2016-01-25 11:09 蓦辰 阅读(191) 评论(0) 推荐(0) 编辑
摘要: /*BFS:二进制状态压缩*/#include #include #include #include #include #include #include #include #include #include using namespace std;#define MAXN 11111#includ... 阅读全文
posted @ 2016-01-25 11:08 蓦辰 阅读(200) 评论(0) 推荐(0) 编辑
摘要: /*BFS:重复访问类关键:对每个点的访问与否取决于到达该点的条件的优劣(本题关键在于访问该点是能量的多少,比原先多的即可走)*/#include #include #include #include #include #include #include #include #include #inc... 阅读全文
posted @ 2016-01-25 11:07 蓦辰 阅读(212) 评论(0) 推荐(0) 编辑
摘要: /* 小水题当个模版*/#include #include #include #include #include #include using namespace std;#include #include #include #include #include #define M 1000 ... 阅读全文
posted @ 2016-01-25 11:06 蓦辰 阅读(144) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#includeusing namespace std;const int MAXN=110010;char s[2*MAXN];//MAXN太大只能放外面int p[MAXN*2];//求给定字符串str的最长回文子串int solv... 阅读全文
posted @ 2016-01-25 11:04 蓦辰 阅读(236) 评论(0) 推荐(0) 编辑
摘要: Dijkstra算法-邻接矩阵形式复杂度:N^2/** Dijkstra算法,邻接矩阵形式:* 复杂度为O(n^2),仅可处理非负权图* cost: 任意两点边权(不相连边需赋值INF)* n: 图中点的总数(当前点从0开始编号)* lowcost:任意点到源点的最短路* beg:... 阅读全文
posted @ 2016-01-25 11:02 蓦辰 阅读(194) 评论(0) 推荐(0) 编辑
摘要: Kruskal 算法复杂度:E log(2E)int F[MAXN];//并查集使用struct Edge{ int u,v,w;}edge[MAXM];//存储边的信息,包括起点/终点/权值int tol;//边数,加边前赋值为0void addedge(int u,int v,int w)... 阅读全文
posted @ 2016-01-25 10:55 蓦辰 阅读(159) 评论(0) 推荐(0) 编辑
摘要: #includeint father[1005];int find(int x){ int r=x; while(father[r]!=r) {//沿着关系一直向上摸索 r=father[r]; } int i=x,k; //压缩 while(... 阅读全文
posted @ 2016-01-25 10:53 蓦辰 阅读(127) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include #include using namespace std;#define M 20int num, mod;//定义矩阵结构体struct mat{ int at[M][M];};struct mat d... 阅读全文
posted @ 2016-01-25 10:50 蓦辰 阅读(131) 评论(0) 推荐(0) 编辑
摘要: int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b);}int Euler(int n){ //给定n,返回1~~(n-1)中与n互质的数的个数 //复杂度nlogn int i; int result;... 阅读全文
posted @ 2016-01-25 10:49 蓦辰 阅读(142) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#includeusing namespace std;#define MAXPRME 100000bool visit[MAXPRME+100];int prime[MAXPRME];//给定n,求所有>n) { ... 阅读全文
posted @ 2016-01-25 10:47 蓦辰 阅读(183) 评论(0) 推荐(0) 编辑
摘要: /*HDU 3473 Minimum Sum求询问区间内 所有数与中位数的差的绝对值的和*/#include#include#include#includeusing namespace std;const int MAXN=200010;int tree[20][MAXN];int sorted... 阅读全文
posted @ 2016-01-25 10:46 蓦辰 阅读(221) 评论(0) 推荐(0) 编辑
摘要: //复杂度log(n)#include #include #include #include #include #include #include #include #include #include #include #includeusing namespace std;#include con... 阅读全文
posted @ 2016-01-25 10:44 蓦辰 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 简化版:(正int输入挂)int read(){ char ch=' '; int ans=0; while(ch'9') ch=getchar(); while(ch='0') { ans=ans*10+ch-'0'; ch=... 阅读全文
posted @ 2016-01-25 10:43 蓦辰 阅读(147) 评论(0) 推荐(0) 编辑
摘要: /**模版原题:PKU 3468*线段树*区间求和*/#include #include using namespace std;#define lson l , m , rt > 1)); // sum[rt*2]+=( add值*其旗下最终子节点个数); sum... 阅读全文
posted @ 2016-01-25 10:35 蓦辰 阅读(211) 评论(0) 推荐(0) 编辑
摘要: /***模版原题:HDU 1754*线段树-单点加减*区间求最值*/#include #define lson l , m , rt > 1; //m=(l+r)/2; build(lson); build(rson); PushUP(rt); //回溯更新父节点}//单点修... 阅读全文
posted @ 2016-01-25 10:34 蓦辰 阅读(117) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;#define DIGIT 4 //四位隔开,即万进制#define DEPTH 10000 //万进制#define MAX 251 //题目最大位数/4,要不大直接设为最大位... 阅读全文
posted @ 2016-01-25 10:31 蓦辰 阅读(156) 评论(0) 推荐(0) 编辑