コード例 #1
0
ファイル: p284_brute.cpp プロジェクト: alxsoares/OI
int main() {
	freopen("t.in", "r", stdin);
	int N;
	scanf("%d", &N);
	scanf("%s", pat);
	patLen = strlen(pat);
	for ( int i = 1; i <= N; i ++ ) {
		int m;
		int accSz = 0;
		scanf("%d", &m);
		for ( int j = 0; j < m; j ++ ) {
			static char ts[5];
			scanf("%s", ts);
			if ( ts[0] == 'a' || ts[0] == 'b' ) 
				acc[accSz++] = ts[0];
			else {
				int t;
				sscanf(ts, "%d", &t);
				memcpy(acc + accSz, comp[t], sizeof(char) * compSz[t]);
				accSz += compSz[t];
			}
		}

		compSz[i] = accSz;
		memcpy(comp[i], acc, sizeof(char) * accSz);
	}
	printf("%d\n", countMatch(comp[N], compSz[N]));
}
コード例 #2
0
ファイル: 235.cpp プロジェクト: CC91/LeetCode
 TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
     if (!root ||p==root ||q==root) return root;
     int match = countMatch(root->left, p, q);
     if (match==1) return root;
     else if (match==2) lowestCommonAncestor(root->left, p, q);
     else lowestCommonAncestor(root->right, p, q);
 }
コード例 #3
0
ファイル: analyze.c プロジェクト: Scorbie/ptbtest
void bestMatches(LifeList *cells1, LifeList *cells2, int period, 
                     int nmatches, PartialOscillatorDesc *osc) {
 
  int nConvolution, nEmpty;
  int i;
  Transformation T, bestT;

  setValues(cells1->cellList, cells1->ncells, 1);
  setValues(cells2->cellList, cells2->ncells, 1);

  T.translateBy= 0;
  for (T.flipxF=0; T.flipxF<=1; T.flipxF++) {
    for (T.flipyF=0; T.flipyF<=1; T.flipyF++) {
      for (T.transposeF=0; T.transposeF<=1; T.transposeF++) {

        transform(cells2->cellList, T, cells2->ncells);
        nConvolution=convolve(cells1->cellList, cells1->ncells, 
                              cells2->cellList, cells2->ncells, 
                              &convolution, &scratch1, &scratch2,
                              makeWorkSpace);

   
        for (i=0; i<nConvolution; i++) { 
          
           
          if (cells1->ncells - convolution[i].value 
                           < osc[nmatches-1].matchDistance) {
            int j,matchDistance; 


            matchDistance = cells1->ncells - convolution[i].value;

            nEmpty =emptyNeighbors(cells1);
            copyList(cells1->neighborhoods, nEmpty,
                     cells1->neighborhoods, convolution[i].position);

            matchDistance+=countMatch(cells1->neighborhoods, nEmpty,
                                      cells2->cellList, cells2->ncells);

            j= nmatches-1;

            while (j>=0 && matchDistance < osc[j].matchDistance) {
                osc[j+1]=osc[j];
                j--; 
            }

            osc[j+1].period=period;
            osc[j+1].T=T;
            osc[j+1].T.translateBy= convolution[i].position;
            osc[j+1].matchDistance=matchDistance;

          }
        }
        transformBack(cells2->cellList, T, cells2->ncells);
      }
    }
  }
}
コード例 #4
0
ファイル: lifelist.c プロジェクト: Scorbie/ptbtest
int matchLifeList(LifeList *cells, LifeList *matchcells, int transl) {
int matches;
/* note: destroys matchcells neighborhood values */

    copyList(matchcells->cellList, matchcells->ncells,
             matchcells->neighborhoods, transl);

    matches=countMatch(matchcells->neighborhoods, matchcells->ncells,
                       cells->cellList, cells->ncells);

    return matches;
}
コード例 #5
0
ファイル: lifelist.c プロジェクト: Scorbie/ptbtest
int interact(LifeList *pat1, LifeList *pat2, int transl) {

/* both pat1 and pat2 are generated one step */

   copyLifeList(pat1, &both);
   mergeLifeLists(&both, pat2, transl);

   generate(pat1);
   generate(pat2);
   generate(&both);

   return !( both.ncells == pat1->ncells + pat2->ncells &&
             pat1->ncells == countMatch(pat1->cellList, pat1->ncells,
                                        both.cellList, both.ncells) &&
             pat2->ncells == matchLifeList(&both, pat2, transl) );

}
コード例 #6
0
ファイル: 235.cpp プロジェクト: CC91/LeetCode
 int countMatch(TreeNode* root, TreeNode* p, TreeNode* q) {
     if (!root) return 0;
     int match = countMatch(root->left, p, q)+countMatch(root->right, p, q);
     if (root==p ||root==q) return ++match;
     else return match;
 }