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

为何直接枚举是0ms,本小白自以为稍微改进了下咋超时了呢

Posted by 0140109051 at 2015-09-01 22:12:23 on Problem 1166
#include <iostream>
#include <cmath>
using namespace std;
int clo[9];
int mov[9];
int t=0;

bool guess();
bool enumerate(int);
int main() {
    for (int i=0; i<9; i++) {
        cin>>clo[i];
    }
    while (!enumerate(t)) {
        t++;
        enumerate(t);
    }
    for (int k=0; k<9; k++) {
        while (mov[k]--) {
            cout<<k+1<<' ';
        }
    }

    return 0;
}

bool enumerate(int t){
   
    for (int i1=0; i1<=t; i1++) {
        for (int i2=0; i2<=t-i1; i2++) {
            for (int i3=0; i3<=t-i2-i1; i3++) {
                for (int i4=0; i4<=t-i2-i3-i1; i4++) {
                    for (int i5=0; i5<=t-i2-i3-i4-i1; i5++) {
                        for (int i6=0; i6<=t-i2-i3-i4-i5-i1; i6++) {
                            for (int i7=0; i7<=t-i2-i3-i4-i5-i6-i1; i7++) {
                                for (int i8=0; i8<=t-i2-i3-i4-i5-i6-i7-i1; i8++) {
                                    for (int i9=0 ; i9<=t-i1-i2-i3-i4-i5-i6-i7-i8; i9++) {
                                        mov[0]=i1;mov[1]=i2;mov[2]=i3;mov[3]=i4;mov[4]=i5;mov[5]=i6;
                                        mov[6]=i7;mov[7]=i8;mov[8]=i9;
                                        if((0 == (i1 + i2 + i4 + clo[0]) % 4) && (0 == (i1 + i2 + i3 + i5 + clo[1])% 4) && (0 == (i2 + i3 + i6 + clo[2]) % 4) && (0 == (i1 + i4 + i5 + i7 +clo[3]) % 4) && (0 == (i1 + i3 + i5 + i7 + i9 + clo[4]) % 4) && (0 ==(i3 + i5 + i6 + i9 + clo[5])% 4) && (0 == (i4 + i7 + i8 + clo[6]) % 4)&& (0 == (i5 + i7 + i8 + i9 + clo[7])% 4) && (0 == (i6 + i8 + i9 + clo[8]) % 4)) {
                                            return true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}

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