posts - 20,  comments - 6,  trackbacks - 0
 1#include<stdio.h>
 2#include<string.h>
 3int nd[16][16];
 4int hash[16];
 5int max;
 6int n;
 7void 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}

25int 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    
posted @ 2009-01-27 14:08 混沌的云 阅读(101) | 评论 (0)编辑 收藏
 1#include<stdio.h>
 2#include<string.h>
 3int 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}
posted @ 2009-01-27 14:07 混沌的云 阅读(199) | 评论 (0)编辑 收藏
 1#include<stdio.h>
 2#include<string.h>
 3#include<stdlib.h>
 4char a[10000][1000];
 5int cmp(const void *a,const void *b)
 6{
 7        return strcmp((char *)a,(char *)b);
 8}

 9int 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}

32int 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
posted @ 2009-01-27 14:06 混沌的云 阅读(192) | 评论 (0)编辑 收藏
 1#include<stdio.h>
 2#include<string.h>
 3int n,m;
 4int a[10],b[10];
 5int max=9999;
 6int hash[10];
 7void 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}

41int 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}
posted @ 2009-01-27 14:06 混沌的云 阅读(163) | 评论 (0)编辑 收藏
 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 }
   
13int 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
posted @ 2009-01-27 14:04 混沌的云 阅读(121) | 评论 (0)编辑 收藏
     摘要:   1#include<stdio.h>  2#include<string.h>  3int main()  4{  5    char nek[1000],bf[1000];  6 ...  阅读全文
posted @ 2009-01-27 14:03 混沌的云 阅读(109) | 评论 (0)编辑 收藏
 1#include<stdio.h>
 2#include<stdlib.h>
 3struct pp
 4{
 5    int x,y,z,t;
 6    struct pp * next;
 7}
;
 8int n,m,b,time;
 9int map[50][50][50];
10int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
11int 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}

44int 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}
posted @ 2009-01-18 22:24 混沌的云 阅读(258) | 评论 (0)编辑 收藏
     摘要:   1#include<stdio.h>  2#include<stdlib.h>  3#include<string.h>  4struct ff{  5    int a,b,c,d; &n...  阅读全文
posted @ 2009-01-18 22:22 混沌的云 阅读(241) | 评论 (2)编辑 收藏

 

#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);
 }

}


posted @ 2009-01-18 22:20 混沌的云 阅读(149) | 评论 (0)编辑 收藏
因为要搞acm,163存代码不方便,就开到这里来了~~~
posted @ 2009-01-18 22:18 混沌的云 阅读(104) | 评论 (0)编辑 收藏
仅列出标题
共2页: 1 2 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜