Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

按照解题报告写的,偶菜,请教大牛为什么TLE?

Posted by bluetiger at 2006-02-15 09:36:07 on Problem 2597
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
int b[81][81],bn[81][81],a[81][2];
int n;
int cmp(const void *a,const void *b)
{
    int a0=*(int*)a,a1=*((int*)a+1),b0=*(int*)b,b1=*((int*)b+1);
    if(a0>b0||a0==b0&&a1>b1)return 1;
    return -1;
}    
int count_matrix(int l)
{
    int i,j,k,p,sum=0;
    for(i=0;i<l-1;i++)
    {
        memset(bn,0,sizeof(bn));
        for(j=0;j<n;j++)
        {
            for(k=0;k<n;k++)
            {
                for(p=0;p<n;p++)
                  bn[j][k]+=b[j][p]*b[p][k];
            }    
        }    
        memcpy(b,bn,sizeof(b));
    }    
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
        sum+=b[i][j];   
    return sum;
}    
int main()
{
    int i,j,l,t,max;
    while(scanf("%d",&n)!=EOF)
    {
        memset(b,0,sizeof(b));
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i][0],&a[i][1]);
            if(a[i][0]>a[i][1]){t=a[i][0];a[i][0]=a[i][1];a[i][1]=t;}
        }    
        qsort(a,n,sizeof(a[0]),cmp);
        t=-10001;l=0;
        for(i=0;i<n;i++)
        {
            if(a[i][0]>=t)
            {
                l++;t=a[i][1];
            }    
        }    
        max=n-l;
        for(i=0;i<n;i++)
          for(j=0;j<n;j++)
            if(a[i][1]<=a[j][0])b[i][j]=1;   
        if(max==0)printf("0 1\n");
        else printf("%d %d\n",max,count_matrix(max));  
    }    
    return 0;
}    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator