摘要: #include <iostream>using namespace std;struct point{ int x; int y;}P[705];int n,sum,tol;int main(){ int i,j,k; while(cin>>n,n) { tol=0; for(i=0;i<n;i++) cin>>P[i].x>>P[i].y; for(i=0;i<n;i++) { for(j=i+1;j<n;j+... 阅读全文
posted @ 2013-05-10 15:40 algorithms爱好者 阅读(61) 评论(0) 推荐(0)
摘要: #include <iostream>#include <string.h>using namespace std;char grid[25][25];int vis[25][25];int n,m,x,y,tol;void DFS(int a,int b){ vis[a][b]=1; if(b+1<=m)//右面 { if(b+1==m) { tol++; } else { if(gri... 阅读全文
posted @ 2013-05-08 22:24 algorithms爱好者 阅读(98) 评论(0) 推荐(0)
摘要: 看了别人代码后才想明白的。还得多加练习搜索题!#include <iostream>using namespace std;char Map[9][9];bool place_c[9];int number_p;int tol;int n,k;bool can_place(int i,int j){ return !place_c[j]&&Map[i][j]=='#';}void DFS(int i){ if(number_p==k) { tol++; return; } if(i>=n) return; int j... 阅读全文
posted @ 2013-04-19 13:54 algorithms爱好者 阅读(82) 评论(0) 推荐(0)
摘要: C语言,数据结构,算法!!! 阅读全文
posted @ 2013-04-18 18:04 algorithms爱好者 阅读(90) 评论(0) 推荐(0)
摘要: #include <iostream>#define M 50005using namespace std;int n,m,fa[M];int find_fa(int x){ while(fa[x]!=x) { x=fa[x]; } return x;}void merg(int x,int y){ if(find_fa(x)!=find_fa(y)) { fa[find_fa(x)]=find_fa(y); }}int main(){ int i,a,b,sum,si=... 阅读全文
posted @ 2013-04-18 14:05 algorithms爱好者 阅读(92) 评论(0) 推荐(0)
摘要: #include <iostream>#include<algorithm>using namespace std;void qsort(int arr[],int sta,int end){ if(sta<end) { int x,i=sta,j=end; x=arr[i]; while(i<j) { while(arr[j]>x&&i<j) { j--; } if(i<j) { arr[i++]=arr[j]; } while(arr[i]<=x&&i<j) { i++; } if(i< 阅读全文
posted @ 2013-04-14 14:52 algorithms爱好者 阅读(108) 评论(0) 推荐(0)
摘要: #include<iostream>using namespace std;const int M = 6010;int V[M][2];int fa[M];int n;int Max(int a,int b){ return a>b?a:b;}void calculator(int node){ int i; for(i=1;i<=n;i++) { if(fa[i]==node) { calculator(i); V[node][1]+=V[... 阅读全文
posted @ 2013-04-08 11:46 algorithms爱好者 阅读(103) 评论(0) 推荐(0)
摘要: 一 数学(Mathematics)1 离散数学(Discrete Mathematics)1.1 图论(Graph Theory)图的遍历(Graph Traversal): DFS, BFS最小生成树(Minimum Spanning Tree): Prim, Kruskal最短路径(Shortest Path): Dijkstra, Floyd传递闭包(Transitive Closure)关节点(Articulation Point - UndiGraph)拓扑排序(Topological Sort - AOV-Network)关键路径(Critical Path - AOE-Netwo 阅读全文
posted @ 2013-03-29 21:04 algorithms爱好者 阅读(157) 评论(0) 推荐(0)
摘要: 插入排序1.直接插入排序原理:将数组分为无序区和有序区两个区,然后不断将无序区的第一个元素按大小顺序插入到有序区中去,最终将所有无序区元素都移动到有序区完成排序。要点:设立哨兵,作为临时存储和判断数组边界之用。实现:VoidInsertSort(NodeL[],intlength){Inti,j;//分别为有序区和无序区指针for(i=1;i<length;i++)//逐步扩大有序区{j=i+1;if(L[j]<L[i]){L[0]=L[j];//存储待排序元素While(L[0]<L[i])//查找在有序区中的插入位置,同时移动元素{L[i+1]=L[i];//移动i--; 阅读全文
posted @ 2013-03-28 18:52 algorithms爱好者 阅读(123) 评论(0) 推荐(0)
摘要: 大数题!有公式!判断阶乘位数! #include <stdio.h> #include <math.h> const double e=2.718281828459; const double pi=3.141582626535; double f(int n) { return n*(log10(n)-log10(e))+0.5*(log10(2)+log10(n)+log10(pi)); } int main() { int t,m,s; scanf("%d",&t); while (t--) { scanf("%d" 阅读全文
posted @ 2013-03-26 20:57 algorithms爱好者 阅读(126) 评论(0) 推荐(0)