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

神奇的构造法,把这个题变成了水题,DFS会T的

Posted by yinjian at 2016-07-29 09:53:53 on Problem 3239
//贴一下DFS吧,虽然T了
#include <stdio.h>

int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        if(n%6!=2&&n%6!=3)
        {
            if(n%2==0)
            {
                for(int i=2;i<=n;i+=2)
                    printf("%d ",i);
                for(int i=1;i<=n-3;i+=2)
                    printf("%d ",i);
                printf("%d\n",n-1);
            }
            else {
                for(int i=2;i<=n-1;i+=2)
                    printf("%d ",i);
                for(int i=1;i<=n-2;i+=2)
                    printf("%d ",i);
                printf("%d\n",n);
            }
        }
        else
        {
            if(n%2==0)
            {
                int k=n/2;
                if(k%2==0)
                {
                    for(int i=k;i<=n;i+=2)
                        printf("%d ",i);
                    for(int i=2;i<=k-2;i+=2)
                        printf("%d ",i);
                    for(int i=k+3;i<=n-1;i+=2)
                        printf("%d ",i);
                    for(int i=1;i<=k-1;i+=2)
                        printf("%d ",i);
                    printf("%d\n",k+1);
                }
                else
                {
                    for(int i=k;i<=n-1;i+=2)
                        printf("%d ",i);
                    for(int i=1;i<=k-2;i+=2)
                        printf("%d ",i);
                    for(int i=k+3;i<=n;i+=2)
                        printf("%d ",i);
                    for(int i=2;i<=k-1;i+=2)
                        printf("%d ",i);
                    printf("%d\n",k+1);
                }
            }
            else
            {
                int k=(n-1)/2;
                if(k%2==0)
                {
                    for(int i=k;i<=n-1;i+=2)
                        printf("%d ",i);
                    for(int i=2;i<=k-2;i+=2)
                        printf("%d ",i);
                    for(int i=k+3;i<=n-2;i+=2)
                        printf("%d ",i);
                    for(int i=1;i<=k+1;i+=2)
                        printf("%d ",i);
                    printf("%d\n",n);
                }
                else
                {
                    for(int i=k;i<=n-2;i+=2)
                        printf("%d ",i);
                    for(int i=1;i<=k-2;i+=2)
                        printf("%d ",i);
                    for(int i=k+3;i<=n-1;i+=2)
                        printf("%d ",i);
                    for(int i=2;i<=k+1;i+=2)
                        printf("%d ",i);
                    printf("%d\n",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