随笔分类 -
水题
-
HDU 1879 继续畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1879并查集我的代码 1 #include <stdio.h> 2 #include <stdlib.h> 3 const int M=10000,N=110; 4 struct edge 5 { 6 int u,v,w; 7 }e[M]; 8 int set[N],n,m; 9 int cmp(const void *a,const void *b)10 {11 return ((edge*)a)->w - ((edge*)b)->w;12 }13 int find(in
阅读全文
-
HDU 1233 还是畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1233赤裸裸的最小生成树Kruskal我的代码 1 #include <stdio.h> 2 #include <stdlib.h> 3 const int M=10000,N=100; 4 struct edge 5 { 6 int u,v,w; 7 }e[M]; 8 int set[N],n,m; 9 int cmp(const void *a,const void *b)10 {11 return ((edge*)a)->w - ((edge*)b)->w;12 }1
阅读全文
-
HDU 1232 畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1232赤裸裸的并查集我的代码 1 #include <stdio.h> 2 const int N=1000; 3 int set[N]; 4 int find(int x) 5 { 6 return set[x]==x ? x : set[x]=find(set[x]); 7 } 8 void merge(int x,int y) 9 {10 set[find(x)]=find(y);11 }12 int main()13 {14 int n,m;15 while (scan...
阅读全文
-
HDU 1032 The 3n + 1 problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1032注意m>n的情况View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int f(int x) 5 { 6 int c=1; 7 while (x!=1) 8 { 9 if (x%2==0) x/=2;10 else x=x*3+1;11 c++;12 }13 return c;14 }15 int main()16 {17 int m,n;18...
阅读全文
-
HDU 1197 Specialized Four-Digit Numbers
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1197View Code 1 #include <stdio.h> 2 int main() 3 { 4 const int A=10000; 5 int s1,s2,s3,a=2992,t; 6 s1=s2=s3=0; 7 while (a<A) 8 { 9 for (s1=0,t=a;t>0;t/=10) s1+=t%10;10 for (s2=0,t=a;t>0;t/=12) s2+=t%12;11 for (s3...
阅读全文
|