int main() { // Open input and output files FILE *fp =fopen("crypt1.in","r"); FILE *fp2 =fopen("crypt1.out","w"); int temp; // temporary variable for input int i; // For loop counter long int count = 0; // The required answer int num1; // 3 digit number int num2; // 2 digit number int N; // The cardinality of the set fscanf(fp, "%d",&N); for ( i = 0 ; i < N ; i ++ ) { fscanf(fp, "%d", &temp); array[temp] = 1; } // printf("%d %d\n", inSet(111,3), inSet(1111,4)); for ( num1 = 111 ; num1 < 999 ; num1 ++ ) { for ( num2 = 11 ; num2 < 99 ; num2 ++ ) { if ( num1 * num2 > 9999 ) break; if ( inSet (num1,3) && inSet(num2,2) ) { if ( inSet (num1*(num2%10), 3) && inSet(num1*(num2/10), 3)) { if ( inSet (num1 * num2, 4) ) { // fprintf(fp2, "%d %d\n", num1, num2); count ++; } } } } } fprintf(fp2, "%ld\n",count); // Close input and output files fclose(fp); fclose(fp2); }
/******************************* * Alignment2SequenceWorkerFactory *******************************/ void Alignment2SequenceWorkerFactory::init() { // ports description QList<PortDescriptor*> portDescs; { QMap<Descriptor, DataTypePtr> inM; inM[BaseSlots::MULTIPLE_ALIGNMENT_SLOT()] = BaseTypes::MULTIPLE_ALIGNMENT_TYPE(); DataTypePtr inSet(new MapDataType(ALN_2_SEQUENCE_IN_TYPE_ID, inM)); Descriptor inPortDesc(BasePorts::IN_MSA_PORT_ID(), Alignment2SequenceWorker::tr("Input alignment"), Alignment2SequenceWorker::tr("A alignment which will be split into sequences")); portDescs << new PortDescriptor(inPortDesc, inSet, true); QMap<Descriptor, DataTypePtr> outM; outM[BaseSlots::DNA_SEQUENCE_SLOT()] = BaseTypes::DNA_SEQUENCE_TYPE(); DataTypePtr outSet(new MapDataType(ALN_2_SEQUENCE_OUT_TYPE_ID, outM)); Descriptor outPortDesc(BasePorts::OUT_SEQ_PORT_ID(), Alignment2SequenceWorker::tr("Output sequences"), Alignment2SequenceWorker::tr("Converted sequences")); portDescs << new PortDescriptor(outPortDesc, outSet, false); } QList<Attribute*> attrs; Descriptor protoDesc(Alignment2SequenceWorkerFactory::ACTOR_ID, Alignment2SequenceWorker::tr("Split Alignment into Sequences"), Alignment2SequenceWorker::tr("Splits input alignment into sequences")); ActorPrototype * proto = new IntegralBusActorPrototype(protoDesc, portDescs, attrs); proto->setPrompter(new Alignment2SequencePrompter()); WorkflowEnv::getProtoRegistry()->registerProto(BaseActorCategories::CATEGORY_ALIGNMENT(), proto); WorkflowEnv::getDomainRegistry()->getById( LocalDomainFactory::ID )->registerEntry( new Alignment2SequenceWorkerFactory() ); }
/*功能是从集合中删除元素i * 将set中的第i位设置成0,表示从集合s中删除了 */ int deleteSet(int i, int set) { if(inSet(i,set)) { set = ~(mypow(2,i-1))&set; } return set; }
bool validArgs(char* argv[]) { // if message or type point to the end of the set then that means that the arguments to the // program are not valid. So return false. Valid means taht both arguments are true. return inSet(OF_Messages, argv[1]) and inSet(OF_Message_Type, argv[2]); }
void CollocationWorkerFactory::init() { QMap<Descriptor, DataTypePtr> m; { m[BaseSlots::DNA_SEQUENCE_SLOT()] = BaseTypes::DNA_SEQUENCE_TYPE(); m[BaseSlots::ANNOTATION_TABLE_SLOT()] = BaseTypes::ANNOTATION_TABLE_LIST_TYPE(); } DataTypePtr inSet(new MapDataType(Descriptor("regioned.sequence"), m)); DataTypeRegistry* dr = WorkflowEnv::getDataTypeRegistry(); assert(dr); dr->registerEntry(inSet); QList<PortDescriptor*> p; QList<Attribute*> a; p << new PortDescriptor(Descriptor(BasePorts::IN_SEQ_PORT_ID(), CollocationWorker::tr("Input data"), CollocationWorker::tr("An input sequence and a set of annotations to search in.")), inSet, true /*input*/); QMap<Descriptor, DataTypePtr> outM; outM[BaseSlots::ANNOTATION_TABLE_SLOT()] = BaseTypes::ANNOTATION_TABLE_TYPE(); p << new PortDescriptor(Descriptor(BasePorts::OUT_ANNOTATIONS_PORT_ID(), CollocationWorker::tr("Group annotations"), CollocationWorker::tr("Annotated regions containing found collocations.")), DataTypePtr(new MapDataType(Descriptor("collocation.annotations"), outM)), false /*input*/, true/*multi*/); static const QString newAnnsStr = CollocationWorker::tr("Create new annotations"); { Descriptor nd(NAME_ATTR, CollocationWorker::tr("Result annotation"), CollocationWorker::tr("Name of the result annotations to mark found collocations.")); Descriptor ad(ANN_ATTR, CollocationWorker::tr("Group of annotations"), CollocationWorker::tr("A list of annotation names to search. Found regions will contain all the named annotations.")); Descriptor ld(LEN_ATTR, CollocationWorker::tr("Region size"), CollocationWorker::tr("Effectively this is the maximum allowed distance between the interesting annotations in a group.")); Descriptor fd(FIT_ATTR, CollocationWorker::tr("Must fit into region"), CollocationWorker::tr("Whether the interesting annotations should entirely fit into the specified region to form a group.")); Descriptor td(TYPE_ATTR, CollocationWorker::tr("Result type"), CollocationWorker::tr("Copy original annotations or annotate found regions with new ones.")); Descriptor id(INC_BOUNDARY_ATTR, CollocationWorker::tr("Include boundaries"), CollocationWorker::tr("Include most left and most right boundary annotations regions into result or exclude them.")); Attribute *nameAttr = new Attribute(nd, BaseTypes::STRING_TYPE(), true, QVariant("misc_feature")); Attribute *typeAttr = new Attribute(td, BaseTypes::STRING_TYPE(), false, NEW_TYPE_ATTR); Attribute *boundAttr = new Attribute(id, BaseTypes::BOOL_TYPE(), false, true); a << typeAttr; a << nameAttr; a << boundAttr; a << new Attribute(ad, BaseTypes::STRING_TYPE(), true); a << new Attribute(ld, BaseTypes::NUM_TYPE(), false, QVariant(1000)); a << new Attribute(fd, BaseTypes::BOOL_TYPE(), false, QVariant(false)); nameAttr->addRelation(new VisibilityRelation(TYPE_ATTR, NEW_TYPE_ATTR)); boundAttr->addRelation(new VisibilityRelation(TYPE_ATTR, NEW_TYPE_ATTR)); } Descriptor desc(ACTOR_ID, CollocationWorker::tr("Collocation Search"), CollocationWorker::tr("Finds groups of specified annotations in each supplied set of annotations, stores found regions as annotations.")); ActorPrototype* proto = new IntegralBusActorPrototype(desc, p, a); QMap<QString, PropertyDelegate*> delegates; { QVariantMap lenMap; lenMap["minimum"] = QVariant(0); lenMap["maximum"] = QVariant(INT_MAX); delegates[LEN_ATTR] = new SpinBoxDelegate(lenMap); delegates[FIT_ATTR] = new ComboBoxWithBoolsDelegate(); QVariantMap typeMap; typeMap[CollocationWorker::tr("Copy original annotations")] = COPY_TYPE_ATTR; typeMap[newAnnsStr] = NEW_TYPE_ATTR; delegates[TYPE_ATTR] = new ComboBoxDelegate(typeMap); } proto->setEditor(new DelegateEditor(delegates)); proto->setValidator(new CollocationValidator()); proto->setIconPath(":annotator/images/regions.png"); proto->setPrompter(new CollocationPrompter()); WorkflowEnv::getProtoRegistry()->registerProto(BaseActorCategories::CATEGORY_BASIC(), proto); DomainFactory* localDomain = WorkflowEnv::getDomainRegistry()->getById(LocalDomainFactory::ID); localDomain->registerEntry(new CollocationWorkerFactory()); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::IterateToFixedpoint() { // We use an iterative data-flow algorithm to propagate the copies // that are available on entry of each block. Add the blocks // in reverse-postorder, this minimizes the number of iterations. StaticList<Block*, 64> worklist; SparseBitVector inWorklist; CFGInfo<Block, Function> cfgInfo(funct_->FirstBlock(), false); auto& postorderList = cfgInfo.PostorderList(); int copyCount = infoList_.Count(); // Add all blocks to the worklist. for(int i = 0; i < postorderList.Count(); i++) { auto block = const_cast<Block*>(postorderList[i]); worklist.Add(block); inWorklist.SetBit(block->Id()); } while(worklist.IsNotEmpty()) { // Extract a block from the worklist. auto block = worklist.RemoveLast(); inWorklist.ResetBit(block->Id()); // Compute the 'in' set, which is the intersection // out the 'out' sets of the predecessors. BitVector inSet(copyCount, false); auto predecessorEnum = block->GetPredecessorEnum(); bool first = true; while(predecessorEnum.IsValid()) { auto predecessorBlock = predecessorEnum.Next(); if(first) { inSet = outSets_[predecessorBlock]; first = false; } else inSet.And(outSets_[predecessorBlock]); } // Save the 'in' set, it's needed later // when we want to eliminate the copies. inSets_.Add(block, inSet); // Now compute the new 'out' set, which is the union of the 'copy' set // with the 'in' set, from which the 'kill' set has been subtracted. // Out(B) = Copy(B) U (In(B) - Kill(B)) BitVector outSet = copySets_[block]; inSet.Difference(killSets_[block]); outSet.Or(inSet); if(outSets_[block] != outSet) { // The 'out' set must be updated, and all successors // must be added to the worklist and reprocessed. outSets_[block] = outSet; auto successorEnum = block->GetSuccessorEnum(); while(successorEnum.IsValid()) { auto successorBlock = successorEnum.Next(); if(inWorklist.IsSet(successorBlock->Id()) == false) { worklist.Add(successorBlock); inWorklist.IsSet(successorBlock->Id()); } } } } }
int Classifier::loadData(string testConf, string pathToSil) { // Open file with testing configuration ifstream tcStream(testConf.c_str()); if (!tcStream.is_open()) { fprintf (stderr, "Could not open %s\n", testConf.c_str()); return 1; } string classId; string folderName; set<string> testImgsNames; while (tcStream.good()) { // Skip comments and empty lines string line; getline(tcStream, line); if (!hasData(line)) continue; else { folderName = line; // Get folder name classId = getClassId(folderName); // Get classId testImgsNames.clear(); while (tcStream.good()) // Get names of test images { getline(tcStream, line); if(!hasData(line)) break; testImgsNames.insert(line); } } // Get pictures from folder string dirPath = pathToSil + folderName; const vector<string>& filenames = getFilesFromFolder(dirPath); #ifdef WIN32 dirPath += "\\"; #else dirPath += "/"; #endif for (int i = 0; i < (int) filenames.size(); i++) { // Store image to corresponding set (test or learning) string imgName = filenames[i]; string imgPath = dirPath + imgName; Mat imgMat = imread(imgPath, 1); if (inSet(imgName, testImgsNames)) { testData[classId].push_back(imgMat); } else { learningData[classId].push_back(imgMat); } } if (testData[classId].size() != testImgsNames.size()) fprintf(stderr, "Warning: Test set for %s is badly defined!\n", classId.c_str()); } // Everything went ok return 0; }
int insertSet(int i, int set) { if(inSet(i, set)==0) return set|mypow(2,i-1); return set; }