1
#include<stdio.h>
2
#include<string.h>
3
int nd[16][16];
4
int hash[16];
5
int max;
6
int n;
7
void dfs(int x,int y,int k)
8

{
9
int i;
10
if(max<y)
11
{
12
max=y;
13
}
14
for(i=0;i<n;i++)
15
{
16
if(hash[i]&&k<=nd[x][i])
17
{
18
hash[i]=0;
19
dfs(i,y+1,nd[x][i]);
20
hash[i]=1;
21
}
22
}
23
return;
24
}
25
int main()
26

{
27
int i,j,k;
28
while(scanf("%d",&n)!=EOF)
29
{
30
for(i=0;i<n;i++)
31
{
32
for(j=0;j<n;j++)
33
{
34
scanf("%d",&nd[i][j]);
35
}
36
}
37
memset(hash,1,sizeof(hash));
38
hash[0]=0;
39
max=-1;
40
dfs(0,1,0);
41
printf("%d\n",max);
42
}
43
}
44
45
#include<stdio.h>2
#include<string.h>3
int nd[16][16];4
int hash[16];5
int max;6
int n;7
void dfs(int x,int y,int k)8


{9
int i;10
if(max<y)11

{12
max=y;13
}14
for(i=0;i<n;i++)15

{16
if(hash[i]&&k<=nd[x][i])17

{18
hash[i]=0;19
dfs(i,y+1,nd[x][i]);20
hash[i]=1;21
}22
}23
return;24
}25
int main()26


{27
int i,j,k;28
while(scanf("%d",&n)!=EOF)29

{30
for(i=0;i<n;i++)31

{32
for(j=0;j<n;j++)33

{34
scanf("%d",&nd[i][j]);35
}36
}37
memset(hash,1,sizeof(hash));38
hash[0]=0;39
max=-1;40
dfs(0,1,0);41
printf("%d\n",max);42
}43
}44
45
1
#include<stdio.h>
2
#include<string.h>
3
int main()
4

{
5
char a[10001],b[10001]=
{0};
6
int i,j,k,c,l,n,hash[4];
7
while(gets(a))
8
{
9
l=strlen(a);
10
memset(hash,0,sizeof(hash));
11
k=0;
12
j=0;
13
c=0;
14
for(i=0;i<l;i++)
15
{
16
if(a[i]=='h'||a[i]=='a'||a[i]=='p'||a[i]=='y')
17
{
18
b[k]=a[i];
19
k++;
20
}
21
}
22
b[k]='\0';
23
l=strlen(b);
24
k=0;
25
for(i=0;i<l;i++)
26
{
27
if(b[i]=='h')
28
{
29
hash[0]++;
30
}
31
if(b[i]=='a')
32
{
33
if((hash[1]+1)<=hash[0])
34
{
35
hash[1]++;
36
}
37
b[i]=' ';
38
39
}
40
if(b[i]=='p')
41
{
42
if((hash[2]+1)<=2*hash[1])
43
{
44
hash[2]++;
45
}
46
b[i]=' ';
47
48
}
49
if(b[i]=='y')
50
{
51
if((hash[3]+1)*2<=hash[2])
52
{
53
hash[3]++;
54
}
55
b[i]=' ';
56
57
}
58
}
59
while(hash[3]&&hash[2]>=2)
60
{
61
c++;
62
hash[0]-=1;
63
hash[1]-=1;
64
hash[2]-=2;
65
hash[3]-=1;
66
}
67
68
69
printf("%d\n",c);
70
}
71
72
}
#include<stdio.h>2
#include<string.h>3
int main()4


{5

char a[10001],b[10001]=
{0};6
int i,j,k,c,l,n,hash[4];7
while(gets(a))8

{9
l=strlen(a);10
memset(hash,0,sizeof(hash));11
k=0;12
j=0;13
c=0;14
for(i=0;i<l;i++)15

{16
if(a[i]=='h'||a[i]=='a'||a[i]=='p'||a[i]=='y')17

{18
b[k]=a[i];19
k++;20
}21
}22
b[k]='\0';23
l=strlen(b);24
k=0;25
for(i=0;i<l;i++)26

{27
if(b[i]=='h')28

{29
hash[0]++;30
}31
if(b[i]=='a')32

{33
if((hash[1]+1)<=hash[0])34

{35
hash[1]++;36
}37
b[i]=' ';38
39
}40
if(b[i]=='p')41

{42
if((hash[2]+1)<=2*hash[1])43

{44
hash[2]++;45
}46
b[i]=' ';47
48
}49
if(b[i]=='y')50

{51
if((hash[3]+1)*2<=hash[2])52

{53
hash[3]++;54
}55
b[i]=' ';56
57
}58
}59
while(hash[3]&&hash[2]>=2)60

{61
c++;62
hash[0]-=1;63
hash[1]-=1;64
hash[2]-=2;65
hash[3]-=1;66
}67
68

69
printf("%d\n",c);70
}71
72
} 1
#include<stdio.h>
2
#include<string.h>
3
#include<stdlib.h>
4
char a[10000][1000];
5
int cmp(const void *a,const void *b)
6

{
7
return strcmp((char *)a,(char *)b);
8
}
9
int zh(char *s, int l)//最小表示法 從return值開始為最小
10

{
11
int i = 0, j = 1, k = 0, t;
12
while (i < l && j < l && k < l)
13
{
14
t = s[(i + k)%l] - s[(j + k)%l];
15
if (!t) ++ k;
16
else
17
{
18
if (t > 0)
19
{
20
i = i + k + 1;
21
}
22
else
23
{
24
j = j + k + 1;
25
}
26
if (i == j) ++j;
27
k = 0;
28
}
29
}
30
return i>j?j:i;
31
}
32
int main()
33

{
34
int n,si,q,l;
35
int i,j,p,c,k;
36
char b[1000],cc[1000];
37
while(scanf("%d",&n)!=EOF)
38
{
39
c=0;
40
memset(a,0,sizeof(a));
41
getchar();
42
for(i=0;i<n;i++)
43
{
44
scanf("%s",b);
45
l=strlen(b);
46
si=zh(b,l);
47
for(j=si,k=0;j<l;j++,k++)
48
{
49
a[i][k]=b[j];
50
}
51
for(j=0;j<si;j++,k++)
52
{
53
a[i][k]=b[j];
54
}
55
a[i][k]='\0';
56
}
57
qsort(a,n,sizeof(a[i]),cmp);
58
c=1;
59
for(i=1;i<n;i++)
60
{
61
if(strcmp(a[i-1],a[i])!=0)
62
c++;
63
}
64
printf("%d\n",c);
65
}
66
}
67
68
#include<stdio.h>2
#include<string.h>3
#include<stdlib.h>4
char a[10000][1000];5
int cmp(const void *a,const void *b)6


{7
return strcmp((char *)a,(char *)b);8
}9
int zh(char *s, int l)//最小表示法 從return值開始為最小 10


{11
int i = 0, j = 1, k = 0, t;12
while (i < l && j < l && k < l)13

{14
t = s[(i + k)%l] - s[(j + k)%l];15
if (!t) ++ k;16
else17

{18
if (t > 0)19

{20
i = i + k + 1;21
}22
else 23

{24
j = j + k + 1;25
}26
if (i == j) ++j;27
k = 0;28
}29
}30
return i>j?j:i;31
}32
int main()33


{34
int n,si,q,l;35
int i,j,p,c,k;36
char b[1000],cc[1000];37
while(scanf("%d",&n)!=EOF)38

{39
c=0;40
memset(a,0,sizeof(a));41
getchar();42
for(i=0;i<n;i++)43

{44
scanf("%s",b);45
l=strlen(b);46
si=zh(b,l);47
for(j=si,k=0;j<l;j++,k++)48

{49
a[i][k]=b[j];50
}51
for(j=0;j<si;j++,k++)52

{53
a[i][k]=b[j];54
}55
a[i][k]='\0';56
}57
qsort(a,n,sizeof(a[i]),cmp);58
c=1;59
for(i=1;i<n;i++)60

{61
if(strcmp(a[i-1],a[i])!=0)62
c++;63
}64
printf("%d\n",c);65
}66
}67
68

1
#include<stdio.h>
2
#include<string.h>
3
int n,m;
4
int a[10],b[10];
5
int max=9999;
6
int hash[10];
7
void dfs(int x,int y)
8

{
9
int i;
10
if(x>n)
11
{
12
return;
13
}
14
if(y<=0)
15
{
16
if(max>x)
17
{
18
max=x;
19
}
20
return;
21
}
22
23
for(i=0;i<n;i++)
24
{
25
if(hash[i])
26
{
27
hash[i]=0;
28
if(y<=b[i])
29
{
30
dfs(x+1,y-2*a[i]);
31
32
}else
33
{
34
dfs(x+1,y-a[i]);
35
}
36
hash[i]=1;
37
}
38
}
39
return;
40
}
41
int main()
42

{
43
int i,j,k,l;
44
while(scanf("%d%d",&n,&m)!=EOF)
45
{
46
for(i=0;i<n;i++)
47
{
48
scanf("%d%d",&a[i],&b[i]);
49
}
50
memset(hash,1,sizeof(hash));
51
max=9999;
52
dfs(0,m);
53
if(max!=9999)
54
printf("%d\n",max);
55
else
56
puts("-1");
57
}
58
}
#include<stdio.h>2
#include<string.h>3
int n,m;4
int a[10],b[10];5
int max=9999;6
int hash[10];7
void dfs(int x,int y)8


{9
int i;10
if(x>n)11

{12
return;13
}14
if(y<=0)15

{16
if(max>x)17

{18
max=x;19
}20
return;21
}22
23
for(i=0;i<n;i++)24

{25
if(hash[i])26

{27
hash[i]=0;28
if(y<=b[i])29

{30
dfs(x+1,y-2*a[i]);31
32
}else33

{34
dfs(x+1,y-a[i]);35
}36
hash[i]=1;37
}38
}39
return;40
}41
int main()42


{43
int i,j,k,l;44
while(scanf("%d%d",&n,&m)!=EOF)45

{46
for(i=0;i<n;i++)47

{48
scanf("%d%d",&a[i],&b[i]);49
}50
memset(hash,1,sizeof(hash));51
max=9999;52
dfs(0,m);53
if(max!=9999)54
printf("%d\n",max);55
else56
puts("-1");57
}58
} 1
#include<stdio.h>
2
#include<string.h>
3
__int64 C(__int64 n, __int64 m)
4
{
5
__int64 i, j;
6
if (m > n/2) m = n - m;
7
for (i = 1, j = 1;i <= m; i++)
8
{
9
j = j * (n + 1 - i) / i;
10
}
11
return j;
12
}
13
int main ()
14

{
15
int i,j,t;
16
__int64 k1,k2,k;
17
__int64 m,n;
18
19
while(scanf("%I64d%I64d",&n,&m)!=EOF&&n||m)
20
{
21
t=m>n?n:m;
22
23
printf("%I64d\n",C(m+n,t));
24
}
25
return 1;
26
}
27
摘要: 1#include<stdio.h> 2#include<string.h> 3int main() 4{ 5 char nek[1000],bf[1000]; 6 ... 閱讀全文
#include<stdio.h>2
#include<string.h>3
__int64 C(__int64 n, __int64 m) 4

{ 5
__int64 i, j; 6
if (m > n/2) m = n - m; 7
for (i = 1, j = 1;i <= m; i++) 8

{ 9
j = j * (n + 1 - i) / i; 10
} 11
return j; 12
} 13
int main ()14


{15
int i,j,t;16
__int64 k1,k2,k;17
__int64 m,n;18

19
while(scanf("%I64d%I64d",&n,&m)!=EOF&&n||m)20

{21
t=m>n?n:m;22
23
printf("%I64d\n",C(m+n,t));24
}25
return 1;26
}27

1
#include<stdio.h>
2
#include<stdlib.h>
3
struct pp
4

{
5
int x,y,z,t;
6
struct pp * next;
7
};
8
int n,m,b,time;
9
int map[50][50][50];
10
int dir[6][3]=
{
{1,0,0},
{-1,0,0},
{0,1,0},
{0,-1,0},
{0,0,1},
{0,0,-1}};
11
int bfs(struct pp * head)
12

{
13
int d,e,f,i;
14
struct pp *p,*q;
15
p=head->next;
16
while(head->next)
17
{
18
for(i=0;i<6;i++)
19
{
20
d=head->next->x+dir[i][0];
21
e=head->next->y+dir[i][1];
22
f=head->next->z+dir[i][2];
23
if(d>=0&&d<b&&e>=0&&e<n&&f>=0&&f<m&&map[d][e][f]==0)
24
{
25
map[d][e][f]=1;
26
if(d==b-1&&e==n-1&&f==m-1)
27
return head->next->t+1;
28
q=(struct pp *)malloc(20);
29
q->t=head->next->t+1;
30
if(q->t>=time)
31
continue;
32
q->x=d;
33
q->y=e;
34
q->z=f;
35
q->next=NULL;
36
p->next=q;
37
p=q;
38
}
39
}
40
head->next=head->next->next;
41
}
42
return 0;
43
}
44
int main()
45

{
46
int i,j,l,t,num;
47
struct pp head;
48
struct pp *p;
49
scanf("%d",&t);
50
while(t--)
51
{
52
scanf("%d%d%d%d",&b,&n,&m,&time);
53
for(i=0;i<b;i++)
54
for(j=0;j<n;j++)
55
for(l=0;l<m;l++)
56
scanf("%d",&map[i][j][l]);
57
if(b+m+n-3>time)
58
{puts("-1");continue;}
59
if(n==1&&m==1&&b==1)
60
{puts("0");continue;}
61
p=(struct pp *)malloc(20);
62
head.next=p;;
63
p->next=NULL;
64
p->x=0;p->y=0;p->z=0;p->t=0;
65
num=bfs(&head);
66
free(p);
67
if(num)
68
printf("%d\n",num);
69
else
70
printf("-1\n");
71
}
72
}
摘要: 1#include<stdio.h> 2#include<stdlib.h> 3#include<string.h> 4struct ff{ 5 int a,b,c,d; &n... 閱讀全文
#include<stdio.h>2
#include<stdlib.h>3
struct pp4


{5
int x,y,z,t;6
struct pp * next;7
};8
int n,m,b,time;9
int map[50][50][50];10

int dir[6][3]=
{
{1,0,0},
{-1,0,0},
{0,1,0},
{0,-1,0},
{0,0,1},
{0,0,-1}};11
int bfs(struct pp * head)12


{13
int d,e,f,i;14
struct pp *p,*q;15
p=head->next;16
while(head->next)17

{18
for(i=0;i<6;i++)19

{20
d=head->next->x+dir[i][0];21
e=head->next->y+dir[i][1];22
f=head->next->z+dir[i][2];23
if(d>=0&&d<b&&e>=0&&e<n&&f>=0&&f<m&&map[d][e][f]==0)24

{25
map[d][e][f]=1;26
if(d==b-1&&e==n-1&&f==m-1)27
return head->next->t+1;28
q=(struct pp *)malloc(20);29
q->t=head->next->t+1;30
if(q->t>=time)31
continue;32
q->x=d;33
q->y=e;34
q->z=f;35
q->next=NULL;36
p->next=q;37
p=q;38
}39
}40
head->next=head->next->next;41
}42
return 0;43
}44
int main()45


{46
int i,j,l,t,num;47
struct pp head;48
struct pp *p;49
scanf("%d",&t);50
while(t--)51

{52
scanf("%d%d%d%d",&b,&n,&m,&time);53
for(i=0;i<b;i++)54
for(j=0;j<n;j++)55
for(l=0;l<m;l++)56
scanf("%d",&map[i][j][l]);57
if(b+m+n-3>time)58

{puts("-1");continue;}59
if(n==1&&m==1&&b==1)60

{puts("0");continue;}61
p=(struct pp *)malloc(20);62
head.next=p;;63
p->next=NULL;64
p->x=0;p->y=0;p->z=0;p->t=0;65
num=bfs(&head);66
free(p);67
if(num)68
printf("%d\n",num);69
else70
printf("-1\n");71
}72
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct dictree 

{
struct dictree *child[26];
int n;
};
struct dictree *newnode()

{
int i;
struct dictree *t;
t=(struct dictree*)malloc(sizeof(struct dictree));
t->n=0;
for(i=0;i<26;i++)t->child[i]=NULL;
return t;
}
struct dictree *root;
int main()

{
char a[1000],b[1000];
int i,j,k,l,n;
struct dictree *s=newnode();
//freopen("d:\\abc.txt","w",stdout);
root=newnode();
s=root;
while(gets(a))
{
if(a[0]=='\0')
{
break;
}
l=strlen(a);
s=root;
for(i=0;i<l;i++)
{
n=a[i]-'a';
if(s->child[n])
s=s->child[n];
else 
{
s->child[n]=newnode();
s=s->child[n];
}
s->n++;
}
}
k=0;
j=0;
while(scanf("%s",b)!=EOF)
{
/**//*if(k)
printf("\n");
else
k++;*/
j=1;
s=root;
for(i=0;i<strlen(b);i++)
{
n=b[i]-'a';
if(s->child[n])
s=s->child[n];
else
{
printf("0\n");
j=0;
break;
}
}
if(j)
printf("%d\n",s->n);
}
}

僅列出標(biāo)題
共2頁: 1 2
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
|---|---|---|---|---|---|---|---|---|---|
| 25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
| 8 | 9 | 10 | 11 | 12 | 13 | 14 | |||
| 15 | 16 | 17 | 18 | 19 | 20 | 21 | |||
| 22 | 23 | 24 | 25 | 26 | 27 | 28 | |||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
常用鏈接
留言簿(1)
隨筆檔案
搜索
最新評論

- 1.?re: HDU1429勝利大逃亡(續(xù))!終于過了,順便學(xué)了位壓縮
-
@phk
ac了的 - --混沌的云
- 2.?re: HDU1429勝利大逃亡(續(xù))!終于過了,順便學(xué)了位壓縮
- 你有沒有ac過 感覺有點(diǎn)問題
- --phk
- 3.?re: STL簡單講解
-
@shǎ崽
囧。。。 - --混沌的云
- 4.?re: STL簡單講解
- zero
- --shǎ崽
- 5.?re: 1195 Open the Lock (HDU)
-
@AekdyCoin
你才是大大。。。回@rz - --混沌的云
