Ejemplo n.º 1
0
int main()
{
  Nef_polyhedron N;
  std::ifstream in("data/cube.nef3.SH");
  in >> N;

  Nef_polyhedron C0, C1, C2;
  C0.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(1, 0, 0, 100)));
  C1.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(0, 1, 0, 100)));
  C2.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(0, 0, 1, 100)));

  Union u;
  u.add_polyhedron(C0);
  u.add_polyhedron(C1);
  u.add_polyhedron(C2);
  u.get_union();
  u.add_polyhedron(N);

  Intersection i;
  i.add_polyhedron(C0);
  i.add_polyhedron(C1);
  i.add_polyhedron(C2);
  i.get_intersection();
  i.add_polyhedron(N);

  return 0;
}
Ejemplo n.º 2
0
int main() {
    
    string  input;
    
    while( cin >> N && N ) {

        E.clear();
        
        int x,  y;
        
        while( cin >> x && x ) {
            getline( cin, input );
            istringstream   is( input );
            while( is >> y )
                E.push_back( make_pair( x, y ) );
        }
        
        int cnt = 0;
        
        for( int i = 1; i <= N; ++i ) {
            U.init( N );
            for( int j = 0; j < E.size(); ++j )
                if( E[j].first != i && E[j].second != i )
                    U.merge( E[j].first, E[j].second );
            if( U.getSets() > 2 )
                ++cnt;
        }
        
        cout << cnt << endl; 

    }
    
}
Ejemplo n.º 3
0
int main() {

    int     T,  N,  V;
    string  S;
    int     IN[26];
    int     OUT[26]; 
    Union<26>   U; 
    
    for( cin >> T; T--; ) {
        
        U.init( 26 ); 
        memset( IN, 0, sizeof( IN ) ); 
        memset( OUT, 0, sizeof( OUT ) ); 
        
        for( cin >> N; N--; ) {
            cin >> S;
            int x = S[0] - 'a',
                y = S[S.size() - 1] - 'a';
            IN[x]++; 
            OUT[y]++; 
            U.merge( x, y );
        } 
        
        bool    yes = true;
        int     cnt = 0;
        for( int i = V = 0; i <26; ++i ) {
            V += IN[i] || OUT[i]; 
            if( IN[i] == OUT[i] )
                continue;
            if( IN[i] - OUT[i] > 1 ||
                IN[i] - OUT[i] < -1 ) {
                yes = false;
                break;
            }
            ++cnt;
        }
        
        if( cnt > 2 || !yes || U.getSets() + V != 27 ) {
            puts( "The door cannot be opened." );
            continue; 
        }
        
        else    puts( "Ordering is possible." );
                
    } 

} 
Ejemplo n.º 4
0
TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc line)
{
    
    TIntermAggregate* node = new TIntermAggregate(EOpSequence);

    node->setLine(line);
    TIntermConstantUnion* constIntNode;
    TIntermSequence &sequenceVector = node->getSequence();
    constUnion* unionArray;

    for (int i = 0; i < fields.num; i++) {
        unionArray = new constUnion[1];
        unionArray->setIConst(fields.offsets[i]);
        constIntNode = addConstantUnion(unionArray, TType(EbtInt, EvqConst), line);
        sequenceVector.push_back(constIntNode);
    }

    return node;
}
Ejemplo n.º 5
0
int main()
{
	#ifdef LOCAL
	freopen("3.in", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
	int T;
	scanf("%d", &T);
	for(int ck=1; ck<=T; ck++)
	{
		scanf("%d%d", &N, &M);
		U.init(N);
		for(int i=1; i<=M; i++)
		{
			char opt;
			int x,y;
			scanf(" %c", &opt);
			if(opt=='U')
			{
				scanf("%d%d", &x, &y);
				U.joint(x,y);
			}
			if(opt=='F')
			{
				scanf("%d%d", &x, &y);
				if(U.judge(x,y)) puts("Yes");
				else puts("No");
			}
			if(opt=='S')
			{
				scanf("%d", &x);
				printf("%d\n", U.query(x));
			}
			if(opt=='D')
			{
				scanf("%d", &x);
				U.disjt(x);
			}
		}
	}
	return 0;
}
Ejemplo n.º 6
0
bool operator==(const Union& a, const Union& b)
{
    if(&a==&b)
        return true;
    if (a.getID()!=b.getID())
    	return false;
    size_t nflds=a.getNumberFields();
    if (b.getNumberFields()!=nflds)
        return false;

    // std::equals does not work, since FieldConstPtrArray is an array of shared_pointers
    FieldConstPtrArray af = a.getFields();
    FieldConstPtrArray bf = b.getFields();
    for (size_t i = 0; i < nflds; i++)
        if (*(af[i].get()) != *(bf[i].get()))
            return false;

    StringArray an = a.getFieldNames();
    StringArray bn = b.getFieldNames();
    return std::equal( an.begin(), an.end(), bn.begin() );
}
Ejemplo n.º 7
0
int main() {
    
    for( cin >> T; T--; ) {
      
        U.init( 26 ); 
        
        for( int i = 0; i < 26; ++i ) {
            G[i].clear(); 
            IN[i] = OUT[i] = 0; 
        }

        for( cin >> N; N--; ) {
            string  input;
            cin >> input;
            int x = input[0] - 'a',
                y = input[input.size() - 1] - 'a';
            IN[x]++;
            OUT[y]++; 
            U.merge( x, y );
            G[x].push_back( input );
        } 

        bool    yes = true;
        int     V = 0,  cnt = 0;
        int     begin_pos = 0; 
        for( int i = 0; i <26; ++i ) {
            V += IN[i] || OUT[i]; 
            if( IN[i] == OUT[i] )
                continue;
            if( IN[i] - OUT[i] > 1 ||
                IN[i] - OUT[i] < -1 ) {
                yes = false;
                break;
            } 
            ++cnt;
            if( IN[i] - OUT[i] == 1 )
                begin_pos = i; 
        }

        // 有两个以上奇度点或者
        // 有不平衡点(出入度相差 1 以上) 或者 
        // 不连通,都判为无欧拉路径 
        if( cnt > 2 || !yes || U.getSets() + V != 27 ) {
            puts( "***" );
            continue; 
        }

        // 下面已经确认有欧拉路径,开始寻路 
        path.clear();
        trace.clear(); 

        // 保证字典序
        for( int i = 0; i < 26; ++i )
            if( G[i].size() > 1 )
                sort( G[i].begin(), G[i].end(), greater<string>() );

        // 注意如果有一个点 入度 = 出度 + 1
        // 必须从这个点开始周游 
        if( begin_pos == 0 )
            while( !IN[begin_pos] && !OUT[begin_pos] )
                ++begin_pos; 
        Tour( begin_pos );

        cout << path.back();
        path.pop_back(); 
        while( path.size() ) {
            cout << '.' << path.back();
            path.pop_back(); 
        }

        cout << endl; 
        
    } 
    
} 
Ejemplo n.º 8
0
 /**
  * @brief operator ==
  * @param lhs
  * @param rhs
  * @return
  */
 bool operator ==(const Union &lhs, const Union &rhs)
 {
     return lhs.isEqual(rhs);
 }
Ejemplo n.º 9
0
TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink)
{   
    constUnion *unionArray = getUnionArrayPointer(); 
    int objectSize = getType().getObjectSize();

    if (constantNode) {  // binary operations
        TIntermConstantUnion *node = constantNode->getAsConstantUnion();
        constUnion *rightUnionArray = node->getUnionArrayPointer();
        TType returnType = getType();

        // for a case like float f = 1.2 + vec4(2,3,4,5);
        if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) {
            rightUnionArray = new constUnion[objectSize];
            for (int i = 0; i < objectSize; ++i)
                rightUnionArray[i] = *node->getUnionArrayPointer(); 
            returnType = getType();
        } else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) {
            // for a case like float f = vec4(2,3,4,5) + 1.2;
            unionArray = new constUnion[constantNode->getType().getObjectSize()];
            for (int i = 0; i < constantNode->getType().getObjectSize(); ++i)
                unionArray[i] = *getUnionArrayPointer(); 
            returnType = node->getType();
            objectSize = constantNode->getType().getObjectSize();
        }
        
        constUnion* tempConstArray = 0;
        TIntermConstantUnion *tempNode;
        int index = 0;
        bool boolNodeFlag = false;
        switch(op) {
        case EOpAdd: 
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] + rightUnionArray[i];
            }
            break;
        case EOpSub: 
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] - rightUnionArray[i];
            }
            break;

        case EOpMul:
        case EOpVectorTimesScalar:
        case EOpMatrixTimesScalar: 
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] * rightUnionArray[i];
            }
            break;
        case EOpMatrixTimesMatrix:                
            if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat) {
                infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", getLine());
                return 0;
            }
            {// support MSVC++6.0
                int size = getNominalSize();
                tempConstArray = new constUnion[size*size];
                for (int row = 0; row < size; row++) {
                    for (int column = 0; column < size; column++) {
                        tempConstArray[size * column + row].setFConst(0.0f);
                        for (int i = 0; i < size; i++) {
                            tempConstArray[size * column + row].setFConst(tempConstArray[size * column + row].getFConst() + unionArray[i * size + row].getFConst() * (rightUnionArray[column * size + i].getFConst())); 
                        }
                    }
                }
            }
            break;
        case EOpDiv: 
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++) {
                    switch (getType().getBasicType()) {
                    case EbtFloat: 
                        if (rightUnionArray[i] == 0.0f) {
                            infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
                            tempConstArray[i].setFConst(FLT_MAX);
                        } else
                            tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
                    break;

                    case EbtInt:   
                        if (rightUnionArray[i] == 0) {
                            infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
                            tempConstArray[i].setIConst(INT_MAX);
                        } else
                            tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
                        break;            
                    default: 
                        infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine());
                        return 0;
                    }
                }
            }
            break;

        case EOpMatrixTimesVector: 
            if (node->getBasicType() != EbtFloat) {
                infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", getLine());
                return 0;
            }
            tempConstArray = new constUnion[getNominalSize()];
            
            {// support MSVC++6.0                    
                for (int size = getNominalSize(), i = 0; i < size; i++) {
                    tempConstArray[i].setFConst(0.0f);
                    for (int j = 0; j < size; j++) {
                        tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j*size + i].getFConst()) * rightUnionArray[j].getFConst()));
                    }
                }
            }
            
            tempNode = new TIntermConstantUnion(tempConstArray, node->getType());
            tempNode->setLine(getLine());

            return tempNode;                

        case EOpVectorTimesMatrix:
            if (getType().getBasicType() != EbtFloat) {
                infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", getLine());
                return 0;
            }  

            tempConstArray = new constUnion[getNominalSize()];
            {// support MSVC++6.0
                for (int size = getNominalSize(), i = 0; i < size; i++) {
                    tempConstArray[i].setFConst(0.0f);
                    for (int j = 0; j < size; j++) {
                        tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j].getFConst()) * rightUnionArray[i*size + j].getFConst()));
                    }
                }
            }
            break;

        case EOpMod:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] % rightUnionArray[i];
            }
            break;
    
        case EOpRightShift:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] >> rightUnionArray[i];
            }
            break;

        case EOpLeftShift:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] << rightUnionArray[i];
            }
            break;
    
        case EOpAnd:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] & rightUnionArray[i];
            }
            break;
        case EOpInclusiveOr:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] | rightUnionArray[i];
            }
            break;
        case EOpExclusiveOr:
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] ^ rightUnionArray[i];
            }
            break;

        case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] && rightUnionArray[i];
            }
            break;

        case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    tempConstArray[i] = unionArray[i] || rightUnionArray[i];
            }
            break;

        case EOpLogicalXor:  
            tempConstArray = new constUnion[objectSize];
            {// support MSVC++6.0
                for (int i = 0; i < objectSize; i++)
                    switch (getType().getBasicType()) {
                    case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break;
                    default: assert(false && "Default missing");
                    }
            }
            break;

        case EOpLessThan:         
            assert(objectSize == 1);
            tempConstArray = new constUnion[1];
            tempConstArray->setBConst(*unionArray < *rightUnionArray);
            returnType = TType(EbtBool, EvqConst);
            break;
        case EOpGreaterThan:      
            assert(objectSize == 1);
            tempConstArray = new constUnion[1];
            tempConstArray->setBConst(*unionArray > *rightUnionArray);
            returnType = TType(EbtBool, EvqConst);
            break;
        case EOpLessThanEqual:
        {
            assert(objectSize == 1);
            constUnion constant;
            constant.setBConst(*unionArray > *rightUnionArray);
            tempConstArray = new constUnion[1];
            tempConstArray->setBConst(!constant.getBConst());
            returnType = TType(EbtBool, EvqConst);
            break;
        }
        case EOpGreaterThanEqual: 
        {
            assert(objectSize == 1);
            constUnion constant;
            constant.setBConst(*unionArray < *rightUnionArray);
            tempConstArray = new constUnion[1];
            tempConstArray->setBConst(!constant.getBConst());
            returnType = TType(EbtBool, EvqConst);
            break;
        }

        case EOpEqual: 
            if (getType().getBasicType() == EbtStruct) {
                if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
                    boolNodeFlag = true;
            } else {
                for (int i = 0; i < objectSize; i++) {    
                    if (unionArray[i] != rightUnionArray[i]) {
                        boolNodeFlag = true;
                        break;  // break out of for loop
                    }
                }
            }

            tempConstArray = new constUnion[1];
            if (!boolNodeFlag) {
                tempConstArray->setBConst(true);
            }
            else {
                tempConstArray->setBConst(false);
            }
            
            tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EvqConst));
            tempNode->setLine(getLine());

            return tempNode;         

        case EOpNotEqual: 
            if (getType().getBasicType() == EbtStruct) {
                if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
                    boolNodeFlag = true;
            } else {
                for (int i = 0; i < objectSize; i++) {    
                    if (unionArray[i] == rightUnionArray[i]) {
                        boolNodeFlag = true;
                        break;  // break out of for loop
                    }
                }
            }

            tempConstArray = new constUnion[1];
            if (!boolNodeFlag) {
                tempConstArray->setBConst(true);
            }
            else {
                tempConstArray->setBConst(false);
            }
            
            tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EvqConst));
            tempNode->setLine(getLine());

            return tempNode;         
        
        default: 
            infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine());
            return 0;
        }
        tempNode = new TIntermConstantUnion(tempConstArray, returnType);
        tempNode->setLine(getLine());

        return tempNode;                
    } else {