摘要: spfa的模板,但是,是用邻接表存边的,但是邻接表神物,不懂邻接表的可以去看我的邻接表随笔 1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 #define xx 10005 7 #define INF 0x2fffffff 8 queue<int>que; 9 int t,pre[xx];//边标号,表头;10 int dis[xx],inque[xx];11 struct 阅读全文
posted @ 2012-08-09 21:18 M_cag 阅读(161) 评论(0) 推荐(0)
摘要: 1 //表示用到了gcd,本身没什么好说的 2 #include<stdio.h> 3 __int64 gcd(__int64 a,__int64 b) 4 { 5 if(b==0) 6 return a; 7 return gcd(b,a%b); 8 } 9 int main() 10 {11 __int64 t,a,b,c,d;12 __int64 x,y,z;13 __int64 i;14 scanf("%I64d",&t);15 while(t--)16 {17 scanf("%I64d%... 阅读全文
posted @ 2012-08-09 20:22 M_cag 阅读(128) 评论(0) 推荐(0)
摘要: 1 //二分查找 2 #include<stdio.h> 3 #include<math.h> 4 #define eps 1e-7 5 double fun(double x) 6 { 7 return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6; 8 } 9 double bin_search(double Y)10 {11 double low=0.0,high=100.0,mid;12 while(high-low>eps)13 {14 mid=(low+high)/2.0;15 if(... 阅读全文
posted @ 2012-08-09 16:55 M_cag 阅读(276) 评论(0) 推荐(0)
摘要: 1 //最基础的top排序 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 #define xx 505 7 int g[xx][xx],indegree[xx]; 8 int n,m; 9 void topsort()10 {11 int i,j,k;12 for(i=1;i<=n;i++)13 {14 for(j=1;j<=n;j++)15 {16 if(indegree[j]==0... 阅读全文
posted @ 2012-08-09 10:08 M_cag 阅读(137) 评论(0) 推荐(0)
摘要: 1 #include<stdio.h> 2 int main() 3 { 4 __int64 a,b,ans; 5 while(scanf("%I64X%I64X",&a,&b)!=EOF) 6 { 7 ans=a+b; 8 if(ans<0) 9 {10 printf("-");11 ans=-ans;12 }13 printf("%I64X\n",ans);14 }15 return 0;16 } 阅读全文
posted @ 2012-08-08 20:24 M_cag 阅读(116) 评论(0) 推荐(0)
摘要: 1 //裸的kruskal,如果不会的多看下并查集吧,不多说了 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 #define maxn 100 7 int fa[maxn],rank[maxn]; 8 struct node 9 {10 int st,nd,ln;11 }edge[maxn*maxn];12 int cmp(node a,node b)13 {14 return a.ln<b.ln;15 }16 void i 阅读全文
posted @ 2012-08-08 17:24 M_cag 阅读(344) 评论(0) 推荐(0)
摘要: /*kruskal的模板,表示建图那里稍微有一点点麻烦, 我用的map建图,忘记了只有27个字母,也可以用ascii码来建图。*/#include<stdio.h>#include<string.h>#include<map>#include<string>#include<algorithm>using namespace std;#define maxn 27int fa[maxn];int rank[maxn];struct node{ int st,int nd,int ln;}edge[maxn*maxn];int cmp( 阅读全文
posted @ 2012-08-08 16:26 M_cag 阅读(223) 评论(0) 推荐(0)
摘要: //我想说的是这题描述有点问题,不清楚,水题就没什么好说的了#include<stdio.h>#define min(x,y)(x)>(y)?(y):(x)int main(){ int t; int n,m,ans,c,i; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); ans=10000000; for(i=1;i<=n;i++) { scanf("%d",&c); ans=min(ans,c); ... 阅读全文
posted @ 2012-08-08 15:12 M_cag 阅读(191) 评论(0) 推荐(0)
摘要: 1 //貌似可以用离散化做,本人菜鸟,搞不定,所以大家将就着看吧。 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 #define max(x,y) (x)>(y)?(x):(y) 7 #define maxn 10000000 8 int fa[maxn]; 9 int rank[maxn];10 int ans;11 int n;12 void init()13 {14 int i;15 for(i=1;i<maxn 阅读全文
posted @ 2012-08-08 14:53 M_cag 阅读(144) 评论(0) 推荐(0)