예제 #1
0
void Test2SATOnBigCNFs(const std::vector<Conjunct> &conjunctions, int variables_amount) {
    try {
        std::vector<Conjunct> conjunctions_copy = conjunctions;
        random_shuffle(conjunctions_copy.begin(), conjunctions_copy.end());

        std::vector<bool> values_of_variables(variables_amount);
        if (TwoSAT(conjunctions, values_of_variables) != TwoSAT(conjunctions_copy, values_of_variables)) 
	    throw std::logic_error("FAIL");
    } catch (const std::exception& ex) {
        throw std::logic_error("Test2SATOnBigGraphs : " + std::string(ex.what()));
    }
}
예제 #2
0
inline void StressTestTwoSAT(const std::vector<Conjunct>& conjunctions, int variables_amount) {
    try {
        std::vector<bool> values_of_variables(variables_amount);
        bool is_satisfiable = TwoSAT(conjunctions, values_of_variables);

        if (!is_satisfiable) {
            bool right_is_satisfiable = false;
            std::vector<bool> value(variables_amount, -1);
            StupidIsSatisfiable(conjunctions, value, 0, right_is_satisfiable);
            if (right_is_satisfiable) throw std::logic_error("FAIL");
            return;
        }
	for (int i = 0; i < conjunctions.size(); ++i) 
        for (int conjunct_index = 0; conjunct_index < conjunctions.size(); ++conjunct_index) {
            Conjunct conjunct = conjunctions[conjunct_index];

            bool conjunct_1 = conjunct.is_positive_[0] ? values_of_variables[conjunct.variable_[0]] :
                                !values_of_variables[conjunct.variable_[0]];
            bool conjunct_2 = conjunct.is_positive_[1] ? values_of_variables[conjunct.variable_[1]] :
                                !values_of_variables[conjunct.variable_[1]];

            if (!(conjunct_1 || conjunct_2)) throw std::logic_error("FAIL"); 
        }
    } catch (const std::exception& ex) {
        throw std::logic_error("TestTwoSAT: " + std::string(ex.what()));
    }
}
예제 #3
0
int main()
{
    int i,n,len,j;
    char s1[9],s2[9];
    freopen("poj3683.txt","r",stdin);
    freopen("poj3683ans.txt","w",stdout);
    while (scanf("%d",&n)!=EOF)
    {
        InitEdge();
        for (i=1;i<=n;i++)
        {
            scanf("%s%s%d",s1,s2,&len);
            wed[i].start=TimeStrToInt(s1);
            wed[i].end=TimeStrToInt(s2);
            wed[i].len=len;
        }
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
            {
                if (i==j) continue;
                if (Conflict(wed[i].start,wed[i].len,wed[j].start,wed[j].len)) AddEdge(i,j+n);
                if (Conflict(wed[i].start,wed[i].len,wed[j].end-wed[j].len,wed[j].len)) AddEdge(i,j);
                if (Conflict(wed[i].end-wed[i].len,wed[i].len,wed[j].start,wed[j].len)) AddEdge(i+n,j+n);
                if (Conflict(wed[i].end-wed[i].len,wed[i].len,wed[j].end-wed[j].len,wed[j].len)) AddEdge(i+n,j);
            }
        if (TwoSAT(n))
        {
            printf("YES\n");
            for (i=1;i<=n;i++) if (ans[i])
            {
                PrintTime(wed[i].start);
                printf(" ");
                PrintTime(wed[i].start+wed[i].len);
                printf("\n");
            }
            else
            {
                PrintTime(wed[i].end-wed[i].len);
                printf(" ");
                PrintTime(wed[i].end);
                printf("\n");
            }
        }
        else printf("NO\n");
    }
    return 0;
}