Damn it
Dustman · 共 10 篇文章
俄罗斯方块
一共三个文件 实现得很恶心,很多代码没效率 SCR.c #include "SCR.h" typedef enum mode_t { CHARACTER = 3, BACKGROUND = 4 } mode_t; static struct termios orig; static unsigned int term_init = 0; void clear(void) { fprintf(stderr, "\033 = 1; ret = tcsetattr(STDIN_FILENO, TCSANOW, &ttystat); if (ret != 0) { perror("tcsetattr…
2009-06-05 20:17 · 评论(0)
Floyd-Warshall
就是求所有顶点对的最短路径长度 #include <iostream> #include <vector> using namespace std; typedef struct{ int vexs[10]; int edges[10][10]; int n; int e; }MGraph; #define INFINITE 2048 void CreateGraphM(MGraph *G){ int N1,N2; cout<<"Enter the number of vertexs and edges: "<<endl; cin>>(G->n)>>(G->e); for(int i=0;i…
2009-06-05 16:35 · 评论(0)
Bellman-Ford Dijkstra SPFA
三种最短路径算法 Dijkstra: #include <iostream> #include <queue> #include <vector> using namespace std; typedef struct{ int vexs[10]; int edges[10][10]; int n; int e; }MGraph; #define INFINITE 2048 void CreateGraphM(MGraph *G){ int N1,N2; int i,j,k; cout<<"Enter the number of vertexs and edges: "<<endl; cin…
2009-06-05 16:33 · 评论(0)
关键路径
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef struct{ int vexs[10]; int edges[10][10]; int n; int e; }MGraph; #define INFINITE 2048 void CreateGraphM(MGraph *G){ int N1,N2; int i,j,k; cout<<"Enter the number of vertexs and edges: "<<endl; cin>>(G->n)>>(G->e…
2009-05-31 15:26 · 评论(0)
找第K大的元素
#include <iostream> #include <vector> using namespace std; #define EXCHANGE(a,b) \ ({typeof(a) _tmp; \ _tmp=a; \ a=b; \ b=_tmp;}) template <typename T> int Partition(vector<T>& arr,int p,int r){ int x=arr[r]; int i=p-1; int j=0; for(j=p;j<=r-1;j++){ if(arr[j]<=x){ i=i+1; EXCHANGE(arr[i],arr[j]); } …
2009-05-31 03:34 · 评论(0)
判断有向图是否有环&拓扑排序
//有向图判断是否有环 #include <iostream> #include <list> #include <vector> #include <algorithm> using namespace std; #define TRUE 1 #define FALSE 0 typedef struct{ int vexs[10]; int edges[10][10]; int n; int e; }MGraph; void CreateGraphM(MGraph *G){ int N1,N2; int i,j,k; cout<<"Enter the number of vertexs a…
2009-05-31 03:30 · 评论(0)
求有向图的强连通分量
#include <iostream> //有向图的强连通分量 //翻转边集 深度优先遍历 using namespace std; typedef struct{ int vexs[10]; int edges[10][10]; int n; int e; }MGraph; void CreateGraphM(MGraph *G){ int N1,N2; int i,j,k; printf("Enter the number of vertexs and edges: \n"); scanf("%d %d",&G->n,&G->e); k=G->n; for(i=0;i<k;i++) sc…
2009-05-31 03:26 · 评论(0)
24点
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; #define EXCHANGE(a,b) \ ({typeof(a) _tmp; \ _tmp=a; \ a=b; \ b=_tmp;}) void permute_opt(vector<int> opt,vector<int> permlist,int index){ if(index==3){ int result; int ERROR=0; char save[3]; result=perm…
2009-05-31 03:02 · 评论(0)
Eratosthens sieve
#include <iostream> #include <set> using namespace std; #include "IO.hpp" void SIEVE(set<int>& primes,int limit){ int index; primes.erase(primes.begin(),primes.end()); for(int i=2;i<limit;i++) primes.insert(i); for(int i=2;i*i<=limit;i++) if(primes.find(i) != primes.end()){ index = 2*i; while(index…
2009-05-31 02:56 · 评论(0)
Miller-Rabin 质数测试
#include <iostream> #include <vector> #include <math.h> #include <time.h> #include <algorithm> using namespace std; unsigned long long MOD_EXP(unsigned long long A,\ unsigned long long B,\ unsigned long long N){ // (A^B)%N unsigned long long D = 1; vector<int> R; while((B!=0)){ R.push_back(B%2); B=…
2009-05-31 02:39 · 评论(0)