Exemplo n.º 1
0
int calc(char s[])
{
    len = strlen(s);
    Manacher(s,len);

    sum[0] = s[0];
    for (int i = 1; i < len; i++)
        sum[i] = sum[i-1]*muts+s[i];

    int res = 0;
    uint tmp;
    int nt = 0;
    hash.clear();
    //odd
    for (int i = 0; i < len; i++)
        if (Mp[i*2+2]%2 == 0)
        {
            int pl = Mp[i*2+2]/2;
            if (i+pl < nt || pl == 0)	continue;
            for (int j = i-pl+1; j <= i; j++)
            {
                tmp = gethashcode(j,i);
                if (hash.find(tmp,i-j+1) != -1)	break;
                hash.insert(tmp,i-j+1);
            }
            nt = i+pl;
        }
    res += hash.N;

    nt = 0;
    hash.clear();
    //even
    for (int i = 0; i < len; i++)
        if (Mp[i*2+3] > 1)
        {
            int pl = Mp[i*2+3]/2;
            if (i+pl < nt || pl == 0)	continue;
            for (int j = i-pl+1; j <= i; j++)
            {
                tmp = gethashcode(j,i);
                if (hash.find(tmp,i-j+1) != -1)	break;
                hash.insert(tmp,i-j+1);
            }
            nt = i+pl;
        }
    res += hash.N;
    return res;
}
Exemplo n.º 2
0
void patchSettingExit()
{
	SendDlgItemMessage(hIpsDlg, IDC_SCREENSHOT_H, STM_SETIMAGE, IMAGE_BITMAP, 0);

	memset(hItemHandles, 0, MAX_NODES);
	memset(hPatchHandlesIndex, 0, MAX_NODES);

	nPatchIndex = 0;
	nNumPatches = 0;

	for (int i = 0; i < MAX_NODES; i++) {
		szPatchFileNames[i][0] = _T('\0');
		szDataNames[i][0] = _T('\0');
	}

	// clear relations
	depTable.clear();
	confTable.clear();
	itemStateTable.clear();

	if (hPreview) {
		DeleteObject((HGDIOBJ)hPreview);
		hPreview = NULL;
	}

	if (hDefPreview) {
		DeleteObject((HGDIOBJ)hDefPreview);
		hDefPreview = NULL;
	}

	DeleteObject(hWhiteBGBrush);

	EndDialog(hIpsDlg, 0);
}
Exemplo n.º 3
0
void read_words(const string filename) {
	assert(!open_word_list);

	ifstream fin(filename.c_str());
	assert(fin.is_open());

	_all_words.clear();

	word_list.clear();
	word_list.push_back("");
	assert(word_list.at(NO_WORD) == "");
	word_map.clear();
	word_map[""] = NO_WORD;		// FIXME: Don't use [] operator

	unsigned i;
	string word;
	while(!fin.eof()) {
		fin >> i >> ws >> word >> ws;

		word_list.push_back(word);
		assert(word_list.at(i) == word);
		word_map[word] = i;	// FIXME: Don't use [] operator
		_all_words.push_back(i);

//		if (word == "*content*") _Word_CONTENT = i;
	}
	assert(word_list.size() == word_map.size());

	cerr << "Read " << word_list.size()-1 << " words from '" << filename << "'\n";

	fin.close();
	open_word_list = true;
}
Exemplo n.º 4
0
void initRTS(int **&tabu,int n) {
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            tabu[i][j] = -INF;
    list_size = 2;
    chaotic = 0;
    moving_average = 0.0;
    steps_since_last_change = 0;
    visitas.clear();
}
Exemplo n.º 5
0
static void clearPatches()
{
	int nChecked = 0;
	for (int i = 0; i < nNumPatches; i++) {
		nChecked = _TreeView_GetCheckState(hIpsList, hPatchHandlesIndex[i]);
		if (nChecked) {
			_TreeView_SetCheckState(hIpsList, hPatchHandlesIndex[i], FALSE);
		}
	}

	// clear ips relation
	itemStateTable.clear();
}
Exemplo n.º 6
0
void InitHatLevData(   // init the global HAT data needed for this pyr level
    const Image& img,  // in
    int          ilev) // in
{
    if (ilev <= HAT_START_LEV) // we use HATs only at upper pyr levs
    {
        hat_g.Init_(img, PatchWidth(ilev));
#if CACHE
        if (TRACE_CACHE) // show results from previous run
            lprintf("[calls %d hitrate %.2f cachesize %d]\n",
                    ncalls_g, double(nhits_g) / ncalls_g, cache_g.size());
        cache_g.clear();
#endif
    }
}
Exemplo n.º 7
0
static void initRelations()
{
	// clear state
	itemStateTable.clear();

	// reset checkbox state
	string datName;
	int nChecked = 0;

	for (int i = 0; i < nNumPatches; i++) {
		nChecked = _TreeView_GetCheckState(hIpsList, hPatchHandlesIndex[i]);
		datName = WtoA(szDataNames[i]);
		lowerString(datName);
		itemStateTable.insert(make_pair(datName, nChecked));
	}
}
Exemplo n.º 8
0
int main() {
  int T, n;
  scanf("%d", &T);
  while(T--) {
    scanf("%d", &n);
    cur.clear();
    for(int i = 0; i < n; i++) {
      scanf("%d", &A[i]);
      if(!cur.count(A[i])) last[i] = -1;
      else last[i] = cur[A[i]];
      cur[A[i]] = i;
    }

    int L = 0, R = 0, ans = 0;
    while(R < n) {
      while(R < n && last[R] < L) R++;
      ans = max(ans, R - L);
      L++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
int main(int argc, char** argv) {
  SatProblem cnf;
  cnf.parse(stdin);

  size_t count = 0;

  while (count < 100) {
    cerr << "count = " << count << endl;

    equivalences.clear();
    implications.clear();
    for (size_t i = 0; i < cnf.clauses.size(); ++i) {
      if (cnf.clauses[i].size() == 0) {
        abort();
      } else if (cnf.clauses[i].size() == 1) {
        addEquivalence(cnf.clauses[i][0], TRUE);
        addEquivalence(invert(cnf.clauses[i][0]), FALSE);
      } else if (cnf.clauses[i].size() == 2) {
        implications[invert(cnf.clauses[i][0])].push_back(cnf.clauses[i][1]);
        implications[invert(cnf.clauses[i][1])].push_back(cnf.clauses[i][0]);
      } else {
        // Do nothing
      }
    }

    done.clear();
    for (hash_map<Lit, vector<Lit> >::const_iterator i = implications.begin();
         i != implications.end(); ++i) {
      vector<Lit> stack;
      // cerr << "Exploring " << i->first << endl;
      explore(i->first, stack);
    }

    vector<Clause> oldClauses = cnf.clauses;
    cnf.clauses.clear();

    for (size_t i = 0; i < oldClauses.size(); ++i) {
      Clause cl = oldClauses[i];
      for (size_t j = 0; j < cl.size(); ++j) {
        cl[j] = normalize(cl[j]);
      }
      cnf.addClause(cl);
    }

    for (size_t i = 0; i < cnf.interfaceVariables.size(); ++i) {
      InterfaceVariable& iv = cnf.interfaceVariables[i];
      for (size_t j = 0; j < iv.second.size(); ++j) {
        Lit oldLit = iv.second[j];
        Lit newLit = normalize(oldLit);
        iv.second[j] = newLit;
      }
    }

    if (equivalences.empty()) break; // No changes

    ++count;
  }

  cnf.unparse(stdout);

  return 0;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
    

   outfile.open("./tree.txt");

    printf("THR = %f\n", THR);
    for (int ini = 0; ini < 9; ini++)
    {
        char temp = '1'+ini;
        AsciiToInt[temp] = ini;
        IntToAscii[ini] = temp;
    }
    for (int ini = 0; ini < 26; ini++)
    {
        char temp = 'a'+ini;
        AsciiToInt[temp] = 9 + ini;
        IntToAscii[9+ini] = temp;
    }
    for (int ini = 0; ini < 26; ini++)
    {
        char temp = 'A'+ini;
        AsciiToInt[temp] = 35 + ini;
        IntToAscii[35+ini] = temp;
    }
    //cout<<AsciiToInt.find('a')->first<<endl;
    //cout<<AsciiToInt.find('a')->second<<endl;
    double total_random_time = 0;
    double random_time , main_time;
    clock_t start_random_time, end_random_time;
    timeval tv, tv1, tvPartition;
    timeval treeover, DSeqover, Camover;
    register int i, j;
    long long subgraphCounterMain;
    generator gen;
      int next_option;
  const char *const short_options = "hi:d:o:r:s:f:";
  const struct option long_options[] = {
        {"help",   0, NULL, 'h'},
        {"input",  1, NULL, 'i'},
        {"Dnodes input",  1, NULL, 'd'},
        {"output", 1, NULL, 'o'},
        {"random", 1, NULL, 'r'},
        {"size",   1, NULL, 's'},
        {"treeflag",   1, NULL, 'f'},       
        {NULL,     0, NULL,  0 }        
    };
    
    char *program_name;
    char input_filename[256], output_directory[256], Dpath[256];

    int verbose = 0;
    strcpy(output_directory, "result");

    program_name = argv[0];
    do {
        next_option = getopt_long (argc, argv, short_options, long_options, NULL);
    
        switch (next_option) {
            case 'h':
                print_usage (stdout, 0);

            case 'i':
                strcpy(input_filename, optarg);
                break;

            case 'd':
                strcpy(Dpath, optarg);
                break;
                
            case 'o':
                strcpy(output_directory, optarg);
                break;
            
            case 'r':
                 num_random_graphs = atoi(optarg);
                break;

            case 's':
                subgraphSize = atoi(optarg);
                break;

            case 'f':
                treeflag = atoi(optarg);
                break;
            
            case '?':
                print_usage (stdout, 1);
                
            case -1:        /* Done with options. */
                break;
            
            default:        /* Something else: unexpected. */
                print_usage (stderr, -1);
        }
    } while (next_option != -1);

 
    if (input_filename == NULL) {
        fprintf(stderr, "Input Argument Error: Please specify an input filename using \"-i <FILE NAME>\".\n");
        print_usage (stderr, -1);
    }
    
    if (subgraphSize == -1) {
        fprintf(stderr, "Input Argument Error: Please specify a motif size using \"-s <MOTIF SIZE>\".\n");
        print_usage (stderr, -1);
    }
    
    num_random_graphs = 0;
   
    subgraph = new int*[subgraphSize];
    for (int i = 0; i < subgraphSize; i++)
        subgraph[i] = new int[subgraphSize+3];   //add two cells on subgraph save the number of nodes, edges

    num = 0;
    printf("Graphlets Size: %d\n", subgraphSize);
    printf("Input Graph: %s\n", input_filename);

    if (!ReadData(input_filename, Dpath))
        return 0;

    g->setPath(output_directory);

    double realStart_t = realtime();

    clock_t startTime = clock();
    gettimeofday(&tv, 0);
    //for main graph
    isRand = false;
    subgraphCounter = 0;
    Enumerate();
    

    gettimeofday(&tvPartition, 0);

    cout<<"partitionTime"<<(tvPartition.tv_sec - tv.tv_sec + (double)(tvPartition.tv_usec - tv.tv_usec) / CLOCKS_PER_SEC)<<endl;
    exit(1);

    int deleted=0;
    vector<std::string> frequentG;
    
    vector< pair<std::string, long long int> > finalTree;
    hash_map<std::string, vector< const std::string* > > degreeSeq;
    hash_map<std::string, long long int> degreeSeqCount;
    /*******************Tree isomorphic*****************************/

    /*
    int treeSize = treeInt.size();
 
    int flag=0;
    
    int countTree =0;
  
    for (hash_map<std::string, long long int>::iterator it = treeInt.begin(); it != treeInt.end(); it++)
    {
        std::string tree1 = it->first;
        cout<<"Tree1 = "<<tree1<<endl;
        long long int tempCount = it->second;

        flag = 0;
    
        countTree++;
        
        for (int vi = 0; vi < finalTree.size(); vi++)
        {

            std::string tree2 = finalTree[vi].first;


            if(treeIso(tree1,tree2))
            {
                finalTree[vi].second = tempCount + finalTree[vi].second;
                flag = 1;
                break;
            }
        }
        if(flag == 0)
        {
            pair<string, long long int> tempPair = make_pair(tree1, tempCount);
            finalTree.push_back(tempPair);
        }
        
    }
    */


 
    /******************write non-isomorphic trees into file***********/
    int frequentTree = 0;
    ofstream fileTree;

    fileTree.open(("resultTree_"+intToString(subgraphSize)+".txt").c_str());

    for (hash_map<std::string, long long int>::iterator it = treeInt.begin(); it != treeInt.end(); it++)
    {
        if(it->second > (THR*subgraphCounter))
        {
            frequentTree++;
            //fileTree<< it->first<<" "<<it->second<<"\n";
        }
    }
    
    fileTree.close();

    printf("OutTree: %d\n", frequentTree);

    treeInt.clear();
    finalTree.clear();
    gettimeofday(&treeover, 0);

    cout<<"Time of dealing with tree after Partition before graph: "<<(treeover.tv_sec - tvPartition.tv_sec + (double)(treeover.tv_usec - tvPartition.tv_usec) / CLOCKS_PER_SEC)<<endl;
    
    /****************************************************************/
    /*****************graph isomorphic********************************/
    int graphSize = graphInt.size();
    //cout<<"graphSize:"<<graphSize<<endl;
    vector<bool> CountedGraph(graphSize, true);

    int flag = 0;
    int flag2 = 0;
    //degree sequence
    /*1210 2013**/
    for (hash_map<std::string, long long int>::iterator it = graphInt.begin(); it != graphInt.end(); it++)
    {
        const std::string *graph1 = &(it->first);

        //cout<<"Graph1 = " << *graph1 <<endl;

        std::string gds1 = graphDegreeSequence(*graph1,subgraphSize,AsciiToInt);
        long long int tempCount = it->second;
        //vector<const std::string*> tempGraphs;
        //tempGraphs.push_back(graph1);

        if(degreeSeqCount.find(gds1)==degreeSeqCount.end())
        {
            degreeSeqCount[gds1] = tempCount;
            vector<const std::string*> tempGraphsTemp;
            tempGraphsTemp.push_back(graph1);
            degreeSeq[gds1] = tempGraphsTemp;
        }
        else
        {
            degreeSeqCount.find(gds1)->second = degreeSeqCount.find(gds1)->second + tempCount;
            degreeSeq.find(gds1)->second.push_back(graph1);
        }

    }

    gettimeofday(&DSeqover, 0);

    cout<<"Time of dealing with Degree sequence: "<<(DSeqover.tv_sec - treeover.tv_sec  + (double)(DSeqover.tv_usec - treeover.tv_usec ) / CLOCKS_PER_SEC)<<endl;

    hash_map<std::string, long long int> finalGraph;
    int countCam = 0;
    for (hash_map<std::string, vector<const std::string*> >::iterator it = degreeSeq.begin(); it != degreeSeq.end(); it++)
    {
        vector<const std::string*> tempV = it->second;//graph strings' address with the same degreeSeq 

        if (degreeSeqCount.find(it->first)->second <= (seqTHR*subgraphCounter))
        {
            continue;
        }

        for (int iv = 0; iv < tempV.size(); iv++)
        {
            string tempCam = *(tempV[iv]);
            //cout<<"tempCam = "<<tempCam<<endl;
            countCam++;
            string cam =  calculateCam(tempCam,subgraphSize,AsciiToInt);
            //cout<<"cam = "<< cam<<endl;

            hash_map<std::string, long long int>::iterator it2 =  finalGraph.find(cam);
            if (it2 == finalGraph.end())
            {

                finalGraph[cam] = graphInt.find(tempCam)->second;
            }
            else
            {
                (it2->second) =  (it2->second) + graphInt.find(tempCam)->second;
            }
        }
        tempV.clear();
    }


    gettimeofday(&Camover, 0);

    cout<<"Time of dealing with Cam: "<<(Camover.tv_sec - DSeqover.tv_sec   + (double)(Camover.tv_usec - DSeqover.tv_usec) / CLOCKS_PER_SEC)<<endl;

    // cout<<"here 3333"<<endl;
    ofstream fileGraph;
    fileGraph.open(("resultGraph_"+intToString(subgraphSize)+".txt").c_str());
    //cout<<"Number of finalGraph : "<<finalGraph.size()<<endl;
    int frequentGraph = 0;
    for (hash_map<std::string, long long int> ::iterator it = finalGraph.begin(); it != finalGraph.end(); it++)
    {
        if (it->second > THR*subgraphCounter)
        {
            frequentGraph ++;
            //fileGraph<< it->first<<" "<<it->second<<"\n";
        }
    }
    printf("OutGraph: %d\n", frequentGraph);
    fileGraph.close();

    /****************************************************************/
    //g->AllocateCounter();
    //std::cout<<"countCam"<<countCam<<std::endl;
    //std::cout<<"degreeSeq:"<<degreeSeq.size()<<std::endl;
    //std::cout<<"finalGraph:"<<finalGraph.size()<<std::endl;
    //std::cout<<"deleted:"<<deleted<<std::endl;
    //std::cout<<"frequentGCount:"<<frequentG.size()<<std::endl;
    
    //g->Extract();

    clock_t end_main_time = clock();
    main_time = difftime(end_main_time, startTime)/(double)CLOCKS_PER_SEC;
    //printf("Time Used for main graph: %f\n", main_time);

    subgraphCounterMain = subgraphCounter;
    //for random graphs
    srand(time(NULL));
    isRand = true;
    long long boz = 0;
    //printf("Number of Random Graphs: %d\n", num_random_graphs);
    for (i = 1; i <= num_random_graphs; i++)
    {
        
        gen.genRandGraph_Edge(g);
        subgraphCounter = 0;
        Enumerate();
        g->Extract();
    }

    if (0 < num_random_graphs)
        g->calculateZSCORE(num_random_graphs, subgraphCounterMain, output_directory);

    for(i = 0; i < subgraphSize; i++)
    {
        delete [] Index[i];
        delete [] childSet[i];
    }

    for (int i = 0; i < subgraphSize; i++)
        delete [] subgraph[i];

    delete [] subgraph;
    delete [] Index;
    delete [] childSet;
    delete [] Visited;
    delete g;
    gettimeofday(&tv1, 0);
    clock_t endTime = clock();
    double total_time = difftime(endTime, startTime)/(double)CLOCKS_PER_SEC;
    printf("Time Used: %f\n", total_time);
    cout<<(tv1.tv_sec - tv.tv_sec + (double)(tv1.tv_usec - tv.tv_usec) / CLOCKS_PER_SEC)<<endl;

    double realEnd_t = realtime();
    cout<<"Total real Time: "<<realEnd_t - realStart_t <<endl;
    printf("=============================\n");
    //printf("graphInt: %d\n", graphInt.size());

    //printf("finalGraph: %d\n", finalGraph.size());
    printf("Tree Cam Count: %d\n", frequentTree);
    printf("Graph Cam Count: %d\n", finalGraph.size());
    printf("Total Cam Count: %d\n", finalGraph.size() + frequentTree);
    printf("Total Number of Subgraphs: %lld\n", subgraphCounter);


    return 0;
}
Exemplo n.º 11
0
int fun(){
    int key = getKey(cur);
    int d;
    queue<Node> q;
    dis.clear();
    pred.clear();
    q.push(cur);
    dis[key] = 0;
    pred[key] = -1;
    Node next;
    Iter it;
    while(!q.empty()){
        cur = q.front(); q.pop();
        if(cur.x == gx && cur.y == gy){
            //backtrace(getKey(cur));
            return dis[getKey(cur)];
        }
        d = dis[getKey(cur)];
        // up;
        next = cur;
        if(next.x>0 &&  tab[next.x-1][next.y] ==0
                && reach(next, next.x+1,next.y)){
            next.a = next.x; next.b = next.y;
            next.x --;
            key = getKey(next);
            it = dis.find(key);
            if(it==dis.end() || it->second > d + 1){
                q.push(next);
                pred[key] = getKey(cur);
                dis[key] = d + 1;
            }
        }
        // dn;
        next = cur;
        if(next.x <h-1 &&tab[next.x+1][next.y]==0 
                && reach(next, next.x-1, next.y)){
            next.a = next.x; next.b = next.y;
            next.x++;
            key = getKey(next);
            it = dis.find(key);
            if(it==dis.end() || it->second > d + 1){
                q.push(next);
                pred[key] = getKey(cur);
                dis[key] = d + 1;
            }
        }
        // left;
        next = cur;
        if(next.y>0 && tab[next.x][next.y-1] ==0 
                &&reach(next, next.x,next.y+1)){
            next.a = next.x; next.b = next.y;
            next.y--;
            key = getKey(next);
            it = dis.find(key);
            if(it==dis.end() || it->second > d + 1){
                q.push(next);
                pred[key] = getKey(cur);
                dis[key] = d + 1;
            }
        }
        // right;
        next = cur;
        if(next.y<w-1&& tab[next.x][next.y+1]==0&&reach(next,next.x,next.y-1)){
            next.a = next.x; next.b = next.y;
            next.y++;
            key = getKey(next);
            it = dis.find(key);
            if(it==dis.end() || it->second > d + 1){
                q.push(next);
                pred[key] = getKey(cur);
                dis[key] = d + 1;
            }
        }
    }
    return -1;
}
Exemplo n.º 12
0
void mapLoadDefaultColour()
{
    if(g_dayColourUnits.size()&&g_nightColourUnits.size())
    {
        return;
    }
    g_dayColourUnits.clear();
    g_nightColourUnits.clear();

    size_t maxTableSize = sizeof(g_roadColourTable) / sizeof(TMapColourEntry);
    for(size_t i = 0; i < maxTableSize; i++){                            //load road
        ColourUnit cUnit;
        cUnit.type = ROAD_ARC_MISC;
        RGBCOLOUR colour = g_navDisplay->getColour(g_roadColourTable[i].colourIndex);
        cUnit.colour.red = colour.red;
        cUnit.colour.green = colour.green;
        cUnit.colour.blue = colour.blue;
        cUnit.colour.alpha = colour.alpha;
        cUnit.typeIndex = i;
        if(g_dayColourUnits.find(g_roadColourTable[i].legend) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
            g_nightColourUnits.insert(ColourPair(g_roadColourTable[i].legend, cUnit));
        }

    }
    TElevationPalette *pElevationPalette = g_navDisplay->getElevationPalette();
    for(size_t i = 0; i < numberOfGradients; i++){                       //load gradient
        ColourUnit cUnit;
        if(i < pElevationPalette->elevationThresholdsCount){
            cUnit.type = GRADIENT_ENABLE;
            TElevationPaletteEntry entry = pElevationPalette->elevationPalette[i];
            cUnit.colour.red = entry.r;
            cUnit.colour.green = entry.g;
            cUnit.colour.blue = entry.b;
            cUnit.colour.alpha = entry.elevation;
        }else{
            cUnit.type = GRADIENT_DISABLE;
        }
        if(g_dayColourUnits.find(STR_GRADIENT[i]) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
            g_nightColourUnits.insert(ColourPair(STR_GRADIENT[i], cUnit));
        }

    }
    maxTableSize = sizeof(g_polyColourTable) /
            sizeof(TPolyMapColourEntry) - 1;                                   //last one is elevation, so skip
    for(size_t i = 0; i < maxTableSize; i++) {                           //load poly
        ColourUnit cUnit;
        cUnit.type = POLY_CITY;
        RGBCOLOUR colour = g_navDisplay->getPolygonFillColour(g_polyColourTable[i].polyClass);
        cUnit.colour.red = colour.red;
        cUnit.colour.green = colour.green;
        cUnit.colour.blue = colour.blue;
        cUnit.colour.alpha = colour.alpha;
        cUnit.typeIndex = i;
        if(g_dayColourUnits.find(g_polyColourTable[i].polyName) == g_dayColourUnits.end())
        {
            g_dayColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
            g_nightColourUnits.insert(ColourPair(g_polyColourTable[i].polyName, cUnit));
        }

    }
    g_currentColourType = DAY;
}
Exemplo n.º 13
0
int main()
{
	freopen("1.in","r",stdin);
	freopen("3.out","w",stdout);
    int totcas;
    scanf("%d",&totcas);
    //totcas = 20;
    hash.init();
    for (int cas = 1; cas <= totcas; cas++)
    {
        //for (int i = 0;i < maxn-10;i++)
        //    s[i] = rand()%1+'a';
        //s[maxn-10] = 0;
        scanf("%s",s);
        len = strlen(s);
        Manacher(s,len);

        sum[0] = s[0];
        mutpower[0] = 1;
        for (int i = 1; i < len; i++)
        {
            mutpower[i] = (long long)mutpower[i-1]*muts%mods;
            sum[i] = (sum[i-1]+(long long)s[i]*mutpower[i])%mods;
        }
        int res = 0;
        int tmp;

        //for (int i = 0;i < len*2+2;i++)
        //    printf("%2d ",Mp[i]);
        //printf("\n");

		if (cas == 10)
		{
			for (int i = 10000;i < len;i++)
				for (int j = i-100;j <= i;j++)
					printf("%d\n",gethashcode(j,i));
		}
        hash.clear();
        //odd
        for (int i = 0; i < len; i++)
            if (Mp[i*2+2]%2 == 0)
            {
                int pl = Mp[i*2+2]/2;
                for (int j = i-pl+1; j <= i; j++)
                {
                    tmp = gethashcode(j,i);
                    if (hash.fint(tmp) != -1)    break;
                    hash.insert(tmp);
                }
            }
        res += hash.N;

        hash.clear();
        //even
        for (int i = 0; i < len; i++)
            if (Mp[i*2+3] > 1)
            {
                int pl = Mp[i*2+3]/2;
                for (int j = i-pl+1; j <= i; j++)
                {
                    tmp = gethashcode(j,i);
                    if (hash.fint(tmp) != -1)    break;
                    hash.insert(tmp);
                }
            }
        res += hash.N;

        printf("Case #%d: %d\n",cas,res);
    }
    return 0;
}
Exemplo n.º 14
0
void YglCacheReset(void) {
   g_TexHash.clear();
}
Exemplo n.º 15
0
/// \todo Make some assertion about # of constit. labels, and/or that
/// they are the lowest numbered ones?
void read_labels(const string filename) {
	assert(!open_label_list);

	ifstream fin(filename.c_str());
	assert(fin.is_open());

	_all_labels.clear();
	_all_constituent_labels.clear();
	_all_terminal_labels.clear();
	_max_label = 0;

	label_list.clear();
	label_map.clear();
	terminal_set.clear();
	constituent_set.clear();

	unsigned i, is_terminal, cnt;
	string label;
	while(!fin.eof()) {
		fin >> i >> ws >> is_terminal >> ws >> cnt >> label >> ws;

		if (i == NO_LABEL)
			label = "";

		label_list.push_back(label);
		assert(label_list.at(i) == label);
		label_map[label] = i;	// FIXME: Don't use [] operator

		if (i != NO_LABEL) {
			_all_labels.push_back(i);
			if (is_terminal) {
				terminal_set.insert(i, true);
				_all_terminal_labels.push_back(i);
			} else {
				constituent_set.insert(i, true);
				_all_constituent_labels.push_back(i);
			}
			if (i > _max_label) _max_label = i+1;
		}
	}
	assert(label_list.at(NO_LABEL) == "");
	assert(label_map[""] == NO_LABEL);	// FIXME: Don't use [] operator
	assert(label_list.size() == label_map.size());
//	assert(label_map.size() == terminal_set.size() + constituent_set.size() + 1);
	terminal_set.lock();
	constituent_set.lock();

/*
	Debug::log(1) << "Read " << constituent_set.size() << " constituents, " << \
			terminal_set.size() << " terminals from '" << filename << "'\n";
*/

	fin.close();
	open_label_list = true;

	if (is_label_string("ADJP")) _Label_ADJP = string_to_label("ADJP");
	if (is_label_string("ADVP")) _Label_ADVP = string_to_label("ADVP");
	if (is_label_string("AUX")) _Label_AUX = string_to_label("AUX");
	if (is_label_string("AUXG")) _Label_AUXG = string_to_label("AUXG");
	if (is_label_string("CC")) _Label_CC = string_to_label("CC");
	if (is_label_string("CD")) _Label_CD = string_to_label("CD");
	if (is_label_string("COLON")) _Label_COLON = string_to_label(":");
	if (is_label_string("COMMA")) _Label_COMMA = string_to_label(",");
	if (is_label_string("CONJP")) _Label_CONJP = string_to_label("CONJP");
	if (is_label_string("DOLLAR")) _Label_DOLLAR = string_to_label("$");
	if (is_label_string("DT")) _Label_DT = string_to_label("DT");
	if (is_label_string("EX")) _Label_EX = string_to_label("EX");
	if (is_label_string("FRAG")) _Label_FRAG = string_to_label("FRAG");
	if (is_label_string("FW")) _Label_FW = string_to_label("FW");
	if (is_label_string("HASH")) _Label_HASH = string_to_label("#");
	if (is_label_string("IN")) _Label_IN = string_to_label("IN");
	if (is_label_string("INTJ")) _Label_INTJ = string_to_label("INTJ");
	if (is_label_string("JJ")) _Label_JJ = string_to_label("JJ");
	if (is_label_string("JJR")) _Label_JJR = string_to_label("JJR");
	if (is_label_string("JJS")) _Label_JJS = string_to_label("JJS");
	if (is_label_string("LS")) _Label_LS = string_to_label("LS");
	if (is_label_string("LST")) _Label_LST = string_to_label("LST");
	if (is_label_string("MD")) _Label_MD = string_to_label("MD");
	if (is_label_string("NAC")) _Label_NAC = string_to_label("NAC");
	if (is_label_string("NN")) _Label_NN = string_to_label("NN");
	if (is_label_string("NNP")) _Label_NNP = string_to_label("NNP");
	if (is_label_string("NNPS")) _Label_NNPS = string_to_label("NNPS");
	if (is_label_string("NNS")) _Label_NNS = string_to_label("NNS");
	if (is_label_string("NP")) _Label_NP = string_to_label("NP");
	if (is_label_string("NPB")) _Label_NPB = string_to_label("NPB");
	if (is_label_string("NX")) _Label_NX = string_to_label("NX");
	if (is_label_string("POS")) _Label_POS = string_to_label("POS");
	if (is_label_string("PP")) _Label_PP = string_to_label("PP");
	if (is_label_string("PRN")) _Label_PRN = string_to_label("PRN");
	if (is_label_string("PRP")) _Label_PRP = string_to_label("PRP");
	if (is_label_string("PRPP")) _Label_PRPP = string_to_label("PRP$");
	if (is_label_string("PRT")) _Label_PRT = string_to_label("PRT");
	if (is_label_string("QP")) _Label_QP = string_to_label("QP");
	if (is_label_string("RB")) _Label_RB = string_to_label("RB");
	if (is_label_string("RBR")) _Label_RBR = string_to_label("RBR");
	if (is_label_string("RBS")) _Label_RBS = string_to_label("RBS");
	if (is_label_string("RP")) _Label_RP = string_to_label("RP");
	if (is_label_string("RRC")) _Label_RRC = string_to_label("RRC");
	if (is_label_string("S")) _Label_S = string_to_label("S");
	if (is_label_string("SBAR")) _Label_SBAR = string_to_label("SBAR");
	if (is_label_string("SBARQ")) _Label_SBARQ = string_to_label("SBARQ");
	if (is_label_string("SINV")) _Label_SINV = string_to_label("SINV");
	if (is_label_string("SQ")) _Label_SQ = string_to_label("SQ");
	if (is_label_string("SYM")) _Label_SYM = string_to_label("SYM");
	if (is_label_string("TO")) _Label_TO = string_to_label("TO");
	if (is_label_string("TOP")) _Label_TOP = string_to_label("TOP");
	if (is_label_string("UCP")) _Label_UCP = string_to_label("UCP");
	if (is_label_string("UH")) _Label_UH = string_to_label("UH");
	if (is_label_string("VB")) _Label_VB = string_to_label("VB");
	if (is_label_string("VBD")) _Label_VBD = string_to_label("VBD");
	if (is_label_string("VBG")) _Label_VBG = string_to_label("VBG");
	if (is_label_string("VBN")) _Label_VBN = string_to_label("VBN");
	if (is_label_string("VBP")) _Label_VBP = string_to_label("VBP");
	if (is_label_string("VBZ")) _Label_VBZ = string_to_label("VBZ");
	if (is_label_string("VP")) _Label_VP = string_to_label("VP");
	if (is_label_string("WDT")) _Label_WDT = string_to_label("WDT");
	if (is_label_string("WHADJP")) _Label_WHADJP = string_to_label("WHADJP");
	if (is_label_string("WHADVP")) _Label_WHADVP = string_to_label("WHADVP");
	if (is_label_string("WHNP")) _Label_WHNP = string_to_label("WHNP");
	if (is_label_string("WHPP")) _Label_WHPP = string_to_label("WHPP");
	if (is_label_string("WP")) _Label_WP = string_to_label("WP");
	if (is_label_string("X")) _Label_X = string_to_label("X");
}