随笔分类 - HDUOJ
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1710C:不要在for循环内定义变量,在函数开始处定义变量View Code #include<stdio.h>#include<string.h>#include<malloc.h>typedef struct tree{ int data ; struct tree *l, *r ;}tree, *tr ;int flag ;tr creat(int *root, int*in, int k){ tr t ; int *p ,m; if(k<=0) return
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1702View Code 1 #include<iostream> 2 #include<cstring> 3 #include<stack> 4 #include<queue> 5 using namespace std ; 6 int main() 7 { 8 int t, n, x ; 9 string str1, str ;10 cin>>t ;11 while(t--)12 {13 stack<int>s ;14 queue&l
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1022View Code 1 #include<iostream> 2 #include<stack> 3 #include<cstring> 4 using namespace std ; 5 int main() 6 { 7 int n, i, j, k, d[18] ; 8 string a, b ; 9 while(cin>>n>>a>>b)10 {11 i = j = k = 0 ;12 stack<int>s ;1
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1870栈模拟:15MSView Code 1 #include<iostream> 2 #include<stack> 3 #include<cstring> 4 using namespace std ; 5 char a[1005] ; 6 stack<char>s ; 7 int main() 8 { 9 while(cin>>a)10 {11 while(!s.empty())12 s.pop() ;13 int len = strle...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1879prim:View Code 1 #include <iostream> 2 #include <cmath> 3 4 using namespace std; 5 #define MAX 99999 6 #define LEN 101 7 int dist[LEN]; 8 int map[LEN][LEN]; 9 bool isvisited[LEN]; 10 11 //初始化 12 void init(){ 13 int i,j; 1...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1875kruskal算法: 140MSView Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 struct node 5 { 6 int x, y ; 7 double z ; 8 }b[6000] ; 9 int set[101], i ;10 double sum ;11 int cmp(const void *a, const void *b)12 {13 struct node
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1233Prim:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define MAX 99999 4 #define M 110 5 int dis[M] ; 6 int map[M][M] ; 7 bool vis[M] ; 8 void init() 9 {10 for(int i=0; i<M; i++)11 for(int j=0; j<M; j++)12 {13 if(i==j) map[i][j]...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1863View Code 1 #include<cstring> 2 #include<iostream> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 struct road 7 { 8 int x,y,l; 9 }ht[10010];10 int set[105];11 int find(int x)12 {13 if(set[x]!=x)14 set[x]=find(se
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1874floyd: 62MSView Code 1 #include<iostream> 2 using namespace std ; 3 #define maxn 210 4 const int oo = 1<<28 ; 5 int map[maxn][maxn] ; 6 int n ; 7 void init() 8 { 9 for(int i=0; i<n; i++)10 for(int j=0; j<n; j++)11 {12 map[i][j] = oo ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2544View Code 1 #include<stdio.h> 2 #include<string.h> 3 const int oo = 1<<28 ; 4 const int maxn = 1005 ; 5 int map[maxn][maxn] ; 6 int visit[maxn] ; 7 int n, m ; 8 int len ; 9 int floyd()10 {11 for(int k=1; k<=len; k++)12 {13 for(int i=
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2647View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 #define M 10005 5 struct node 6 { 7 int degree ; 8 int v ; 9 int money ;10 node *next ;11 }s[M] ;12 int q[M*100], mark[M] ;13 int find(int a, int b)14 {15 n...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2094View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 #define maxn 1005 5 int main() 6 { 7 int n, i, j ; 8 char a[maxn][100], b[maxn][100] ; 9 int c[maxn], sum[maxn] ;10 while(cin>>n,n!=0)11 {12 memset(...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1285View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 #define maxn 501 5 int map[maxn][maxn] ; 6 int indegree[maxn], ans[maxn] ; 7 int topological(int n) 8 { 9 for(int i=1; i<=n; i++)10 {11 int j = 1 ;12 wh...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2141View Code 1 #include<iostream> 2 #include<cstdlib> 3 using namespace std ; 4 #define maxn 505 5 int a[maxn], b[maxn], c[maxn] ; 6 int ab[maxn*maxn] ; 7 int cmp(const void *a, const void *b) 8 { 9 return *(int *)a - *(int *)b ;10 }11 int find(
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1016 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 int vis[20], a[20] ; 5 bool prime[40
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1253View Code 1 #include<stdio.h> 2 #include<iostream> 3 using namespace std ; 4 #include<queue> 5 const int INF=10000 ; 6 const int MAX=70 ; 7 int a, b, c, t ; 8 struct node 9 {10 int x, y, z ;11 int time ;12 } ;13 14 int dir[6][3]={{0,0,1
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1312View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std ; 4 char map[21][21] ; 5 bool v[21][21] ; 6 int w, h ; 7 int ans ; 8 int dir[4][2] = { {-1,0}, {0,1}, {1,0}, {0,-1} }; 9 void dfs( int x, int y )10 {11 for( int i=0; i&l
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1228View Code 1 #include <iostream> 2 using namespace std; 3 string strnum[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1305同上题一样,判断一个串是不是另一个串的子串,用的是模拟二叉树View Code 1 #include<stdio.h> 2 struct trie 3 { 4 int num; 5 trie *child[2]; 6 trie() 7 { 8 for(int i=0;i<2;i++) child[i]=0; 9 num=0;10 }11 } *root;12 int flag;13 void Insert(char *x)14 {...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1272View Code 1 #include <stdio.h> 2 int father[100001],k[100001]; 3 int flag ; 4 int find(int x) 5 { 6 while(x!=father[x]) 7 x = father[x] ; 8 return x ; 9 }10 void merge(int x,int y)11 {12 int fx , fy ;13 fx = find(x) ;14 fy = find...
阅读全文

浙公网安备 33010602011771号