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

贴一下代码:暴力判断更新每两个数之间的大小关系,二进制存储每个数的出度判断序列是否成型

Posted by 446101 at 2014-11-07 10:01:29 on Problem 1094
In Reply To:WA之后发现自己复制sample output把每次成功都写成了4次判断之后,,醉了醉了 Posted by:446101 at 2014-11-07 09:57:52
> 》》
#include <cstdio>
#define maxn 26
using namespace std;
int f[maxn][maxn];
int i,j;
int c_son[maxn];
int k,l,m,n,achieve,done;
int ans[maxn];
int pop,son;
int main()
{
    while(1)
    {
        scanf("%d%d\n",&n,&m);
        if(!(n||m))break;                     //initialization
        done=0;
        achieve=n+1;
        for(i=0; i<n; i++)for(j=0; j<n; j++)f[i][j]=0;
        for(i=0; i<n; i++)f[i][i]=1;
        for(i=0; i<n; i++)c_son[i]=0;
        for(i=1; i<=m; i++)
        {
            son=getchar()-'A';
            getchar();
            pop=getchar()-'A';
            getchar();
            if(f[son][pop])
            {
                done=-1;
                printf("Inconsistency found after %d relations.\n",i);
                for(; i<m; i++)
                {
                    getchar();
                    getchar();
                    getchar();
                    getchar();
                }
                break;
            }
            else
            {
                for(j=0; j<n; j++)for(k=0; k<n; k++)
                        if((!f[j][k])  &  f[j][pop]  &  f[son][k])
                        {
                            f[j][k]=1;
                            achieve+=(1<<c_son[j]);
                            c_son[j]++;
                        }
                if(achieve==(1<<n))
                {
                    done=i;
                    for(; i<m; i++)
                    {
                        getchar();
                        getchar();
                        getchar();
                        getchar();
                    }
                break;
                }                
            }
        }
        if(done==-1)continue;
        if(!done)printf("Sorted sequence cannot be determined.\n");
        else
        {
            for(i=0;i<n;i++)ans[c_son[i]]=i;
            printf("Sorted sequence determined after %d relations: ",done);
            for(i=0;i<n;i++)printf("%c",(char)'A'+ans[i]);
            printf(".\n");
        }
    }
    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