随笔分类 - acm训练
摘要:View Code 1 #include<stdio.h> 2 #define MAXV 100 3 #define INF 32767 4 //#include"graph.h" 5 6 void DispMat(MGraph g) 7 { 8 int i,j; 9 for(i=0;i<g.n;i++) 10 { 11 for(j=0;j<g.n;j++) 12 if(g.edges[i][j]==INF) 13 printf("%3s","∞"); 14 else 15 ...
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1301题目大意:输入一个n,表示有n个村庄,然后下面是n-1行,每行开头有两个代表字母和数字,分别表示 起始点和与其相同的村庄的个数。然后就是与其相同的村庄和道路长度,求最小连通值。代码View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int map[30][30]; 5 int vis[30]; 6 int prim(int n) 7 { 8 int ans = 0
阅读全文
摘要:赤裸裸的最小生成树。题目大意就是输入一个N表示有n个村庄,然后输入n行n列,第i行j个元素表示i村庄离j村庄的路数多远(所以i行i列一般为零),然后输入q,表示q条路已修,然后输入q对数就可以了。(权值为零)。求使其n个村庄最小的连通值。需要注意的是可能会有重复的路出现,但是有不同的值。既然是求最小生成树,那么可以用prim算法在输入路的时候保证是最小的值。代码如下View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int map[105][105]; 5 int
阅读全文
摘要:hdu 1879 继续畅通工程 克鲁斯 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 typedef struct node 5 { 6 int u,v,w; 7 }edge; 8 edge e[10005]; 9 int dg[105];10 void init(int n)11 {12 int i;13 for(i = 1;i <=n ;i++)14 dg[i] = i;15 }16 int cmp(const void *a,const void *b)17 {18
阅读全文
摘要:最近做了点并查集的题,感觉也挺简单的。下面对我这段时间关于并查集的学习,做一下小结。并查集的作用:并和查,即合并和查找,将一些集合合并,快速查找或判断某两个集合的关系,或某元素与集合的关系,或某两个元素的关系。并查集的结构:并查集主要操作对象是森林,树的结构赋予它独特的能力,对整个集合操作转换为对根节点(或称该集合的代表元素)的操作,一个集合里的元素关系不一定确定,但相对于根节点的关系很明了,这也是为了查找方便。并查集优化方法:按秩合并和路径压缩的配合使用,使得查找过程优化到极致。按秩合并,每次将深度小的树合并到深度大的树里面去,使得整棵树尽量矮;路径压缩,将当前节点到根节点路径上的所有点直接
阅读全文
摘要:题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1285纯粹的拓扑排序View Code 1 #include <stdio.h> 2 #include <string.h> 3 int count,n,in[505],map[505][505],vis[505],sort[505]; 4 5 void topo(int x) 6 { 7 vis[x] = 1; 8 sort[count] = x; 9 count++;10 int i;11 for(i = 1;i <= n;i++)12 {13...
阅读全文
摘要:题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2094对于是否有环,是通过一个N(节点数)的循环来判定。检查并更新每个节点的入度数。每找到一个入度唯一的节点就是它的临边取消,即让他的下个节点的入度减一;最后看看入度为0的节点数是否为N。这道题我还多加了个判断看看是否含有多个冠军的可能。这道题倒是没有那么麻烦,没打用到拓扑。View Code 1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 char str[1005]; 6 }a[1005]; 7
阅读全文
摘要:这道题数据比较大,得用领阶表,表示压力很大。。。。这道题有两个地方值得注意。第一个地方就是怎么确定是否有环,确定的办法就是就是根据离散数学(离散86,烧包加雄起~)的入度来说,当遍历一边并且更新后查找入度为零的点应该有N个(一共N个点)。用一个计数器num去计算是否为n。第二个地方就是方向思维。按理说我们应该用大的作小的父亲,但是当我们建立完一个拓扑表以后,我们如果按照以大的作为父亲的话,我们在计算最顶端的权值(暂且叫为权值吧),即最高点的薪水时,用起点与后续节点相比较加一时不准的,因为后面节点的值会随着向后遍历而改变,而对于遍历完的值无法改变。所以我们不如去找最为固定的点,即最小薪水的点,来
阅读全文
摘要:不大明白啥叫记忆化搜索,但是PC学长说就相当于打表~不大懂= =。。。回头好好看一下题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1501参考着崔老师的代码来的。View Code 1 #include<stdio.h> 2 #include<string.h> 3 4 char s1[205],s2[205],s3[410]; 5 int len,count,vis[205][205],leap; 6 void dfs(int a,int b,int c) 7 { 8 if(leap) 9 return;10 if(v..
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1372大体意思是给你一个8*8的棋盘,然后给你两个字母与数字的组合,字母代表的是行,数字代表咧,让你找出从第一个组合的位置到第二个组合的位置,至少要走多少步。View Code 1 #include<stdio.h> 2 #include<string.h> 3 struct node 4 { 5 int x,y,step; 6 }q[100005]; 7 int map[15][15]; 8 int pro[15][15]; 9 int to[8][2] = {{2,1},
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1253三维的BFS,跟地下城那道题很像。不用怎么解释。题目上说的很清楚。View Code 1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 int x,y,z; 6 int t; 7 }q[1000005]; 8 int map[55][55][55]; 9 int pro[55][55][55],f,r;10 int to[6][3] = {{0,0,1},{0,0,-1},{0,1,0},{0,-
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1241题目大意是@是可以走的,让你找出是不是有几块是连载一起的。跟挑战编程上的一道题木很想、View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 char map[110][110]; 5 int vis[110][110]; 6 int to[8][2] = {{0,1},{0,-1},{1,0},{1,1},{1,-1},{-1,0},{-1,1},{-1,-1}}; 7 int n,m,count; 8 9 vo
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1015题目的大意就是给以一串字符串和一个目标数字,让你从中找出5个字母,依次可以满足v - w^2 + x^3 - y^4 + z^5 = target这个关系式如果有多个就按字典序最大的输出。。。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>int vis[100005];char str[100005];int sum,leap;char end[10],temp[10];in
阅读全文
摘要:题目理解听想人,就是看有没有办法让b变成m。View Code 1 #include<stdio.h> 2 #include<string.h> 3 int q[100000]; 4 int map[30][30]; 5 int pro[100000]; 6 int f,r; 7 8 int main() 9 {10 int n,i,j,len,leap;11 char s[200];12 while(scanf("%s",s) != EOF)13 {14 leap = 0;15 memset(map,0,sizeof(map...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2251这道题坑爹的地方在于。。。我很悲剧的一个变量写错了~View Code #include <iostream>#include <stdio.h>#include <string.h>using namespace std;char map[35][35][35];int pro[35][35][35];int fro,re;struct node{ int l,r,c,step;}q[100005],v;int main(){ int r,l,c,i,j,k,leap,ii,jj,num
阅读全文
摘要:一开始我看见那个simple out的时候很无语比我的数差好多感觉好大,以为是应该用2进制表示后来发现时special judge~~开始的时候数组要开的大一点。。。我re了两次没找到错然后加了3个零然后A掉View Code #include <stdio.h>__int64 q[10000005],res;int f,r;int main(){ __int64 n,i; while(scanf("%I64d",&n)&&n) { f = r = 0; q[r++] = 1; while(f != r) { ...
阅读全文
摘要:题目连接http://poj.org/problem?id=3278一开始作者道题的时候re了好几次。不知道为什么后来交的时候又WA然后发现得分情况一种是大于等于一种是小于一天刚学会就A了三道题比较满意。View Code #include<stdio.h>#include<string.h>struct node { int step; int i;}q[500005];int pro[500005];int fro,re;int main(){ int farm,cow; while(scanf("%d %d",&farm,&co
阅读全文
摘要:fro < re 然后用结构体记录上一步的步数。View Code 图结构练习——BFS——从起始点到目标点的最短步数#include<stdio.h>#include<string.h>int map[1005][1005];struct node{ int i; int count;} q[2005];int pro[1005];int fro;int re;int main(){ int d,e,s,i,j,a,b,t; while(scanf("%d %d",&d,&e) != EOF) { memset(map,0,s
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>int map[105][105];int q[210];int pro[105];int fro;int re;int main(){ int d,e,s,i,j,a,b,t; scanf("%d",&t); while(t--) { memset(map,0,sizeof(map)); memset(pro,0,sizeof(pro)); scanf("%d %d %d",&d,&e,&s); for(i
阅读全文
摘要:典型的字典树使用一个flag来标记是否是一个句子。现在我们可以用一个cout来标记这条路径是否有单词存在过,存在过几次连接http://poj.org/problem?id=2001View Code #include <iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;struct node{ int count;//用来存有多少个单词存在过。 int next[27];}word[20100];int num = 0;char s
阅读全文

浙公网安备 33010602011771号