Skip to content

Commit 09be015

Browse files
committed
add mul0
1 parent 66db133 commit 09be015

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

docs/codingprob/FDS/hw/ham.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#define N 210
5+
int n,m,k,g[N][N]={0},ord[N],n1,a[N*2],vis[N];
6+
int chk()
7+
{
8+
if(n1!=n+1||a[0]!=a[n1-1])
9+
return 0;
10+
memset(vis,0,sizeof(vis));
11+
int i,j;
12+
for(i=0;i<n1-1;i++)
13+
{
14+
vis[a[i]]=1;
15+
if(!g[a[i]][a[i+1]])
16+
return 0;
17+
}
18+
vis[a[n1-1]]=1;
19+
for(i=1;i<=n;i++)
20+
{
21+
if(!vis[i])
22+
return 0;
23+
}
24+
return 1;
25+
}
26+
int main()
27+
{
28+
int i,j,x,y;
29+
30+
scanf("%d%d",&n,&m);
31+
for(i=0;i<m;i++)
32+
{
33+
scanf("%d%d",&x,&y);
34+
// printf("Edge number %d: %d %d\n",i+1,x,y);
35+
g[x][y]=1;
36+
g[y][x]=1;
37+
}
38+
//printf("Edge input done\n");
39+
scanf("%d",&k);
40+
while(k--)
41+
{
42+
scanf("%d",&n1);
43+
for(i=0;i<n1;i++)
44+
{
45+
scanf("%d",&a[i]);
46+
}
47+
/* printf("Path input *************\n");
48+
for(i=0;i<n1;i++)
49+
{
50+
printf("%d ",a[i]);
51+
}
52+
printf("\n");*/
53+
if(chk())
54+
printf("YES\n");
55+
else
56+
printf("NO\n");
57+
}
58+
}

docs/codingprob/FDS/hw/ham.exe

18 KB
Binary file not shown.

docs/codingprob/FDS/hw/topo.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
typedef enum {false, true} bool;
5+
#define MaxVertexNum 10 /* maximum number of vertices */
6+
typedef int Vertex; /* vertices are numbered from 1 to MaxVertexNum */
7+
8+
typedef struct AdjVNode *PtrToAdjVNode;
9+
struct AdjVNode{
10+
Vertex AdjV;
11+
PtrToAdjVNode Next;
12+
};
13+
14+
typedef struct Vnode{
15+
PtrToAdjVNode FirstEdge;
16+
} AdjList[MaxVertexNum];
17+
18+
typedef struct GNode *PtrToGNode;
19+
struct GNode{
20+
int Nv;
21+
int Ne;
22+
AdjList G;
23+
};
24+
typedef PtrToGNode LGraph;
25+
26+
LGraph ReadG(); /* details omitted */
27+
28+
bool IsTopSeq( LGraph Graph, Vertex Seq[] );
29+
30+
int main()
31+
{
32+
int i, j, N;
33+
Vertex Seq[MaxVertexNum];
34+
LGraph G = ReadG();
35+
scanf("%d", &N);
36+
for (i=0; i<N; i++) {
37+
for (j=0; j<G->Nv; j++)
38+
scanf("%d", &Seq[j]);
39+
if ( IsTopSeq(G, Seq)==true ) printf("yes\n");
40+
else printf("no\n");
41+
}
42+
43+
return 0;
44+
}
45+
46+
/* Your function will be put here */
47+
bool IsTopSeq( LGraph Graph, Vertex Seq[] )
48+
{
49+
int p[10010], i, j;
50+
for(i=0;i<Graph->Nv;i++)
51+
{
52+
p[Seq[i]-1]=i;
53+
}
54+
for(i=0;i<Graph->Nv;i++)
55+
{
56+
PtrToAdjVNode edge=Graph->G[i].FirstEdge;
57+
while(edge)
58+
{
59+
if(p[edge->AdjV]<p[i])
60+
{
61+
return false;
62+
}
63+
edge=edge->Next;
64+
}
65+
}
66+
return true;
67+
}

0 commit comments

Comments
 (0)