Example #1
0
int main() {
		// Taking input of number of testcases to be solved.
		uint32_t testcases =  g_fi.ReadNext();


		//Loop to go through process number of testcases time.
		for (uint32_t i = 0; i < testcases; ++i) {
			
				// This map will hold the level wise total score of soint.
				map<int,int> sointlevelscore;
				// This map will hold the level wise total score of sofloat.
				map<int,int> sofloatlevelscore;


				// Inputing number of Warriers in each team Soint and soFloat
				uint32_t sointN = g_fi.ReadNext();
				uint32_t sofloatM = g_fi.ReadNext();
				
				for ( uint32_t j  = 0;j < sointN ; j++ ) {
					uint32_t chakra = g_fi.ReadNext();
					uint32_t level = g_fi.ReadNext();
					if (sointlevelscore.find(level) == sointlevelscore.end()) {
						sointlevelscore[level] = chakra;
					} else {
						sointlevelscore[level] = sointlevelscore.find(level)->second + chakra;
					}
				}

				for ( uint32_t j  = 0;j < sofloatM ; j++ ) {
					uint32_t chakra = g_fi.ReadNext();
					uint32_t level = g_fi.ReadNext();
					if (sofloatlevelscore.find(level) == sofloatlevelscore.end()) {
						sofloatlevelscore[level] = chakra;
					} else {
						sofloatlevelscore[level] = sofloatlevelscore.find(level)->second + chakra;
					}
				}
				int minimumchakra = 0;
	//To check how much time actual logic takes
/*
				map<int,int>::iterator chakrainterator;
				for ( chakrainterator = sointlevelscore.begin();chakrainterator != sointlevelscore.end();chakrainterator++) {
					int score = ( sofloatlevelscore[(*chakrainterator).first] - (*chakrainterator).second ); 
					if ( score > 0 ) {
						minimumchakra += score; 						
					}
				}
*/

				g_fo.PrintUint(minimumchakra, '\n');
		}
		g_fo.Flush();
		return 0;
}
int main() {
		uint32_t testcases = g_fi.ReadNext();
/*				max2 = (float **)calloc(2000,  sizeof(float*));
				used = (int **)calloc(2000  ,  sizeof(int *));
				for (int r = 0; r < 2000;r++) {
					max2[r] = (float *)calloc(2000  ,  sizeof(float));
					used[r] = (int *)calloc(2000  ,  sizeof(int));
				}*/
//			memset(max2, 0, sizeof(float)*2000*2000);
			memset(used, 0, sizeof(int)*2000);

		for (tc = 0; tc < testcases; ++tc) {
				 //cout<<"Test Cases  "<<i<<endl;
				 NumberofDiamonds =  g_fi.ReadNext();
				diamonds = (int *)malloc(NumberofDiamonds*sizeof(int *));
				for (int r = 0; r < NumberofDiamonds;r++) {
						uint32_t S = g_fi.ReadNext();
						diamonds[r] = S;
					}
				
		
				//This variable will be used to maintain the index of the  lookup table which will help in DP
				int index = 1;

				//Building the lookup table for the dynamic program max2 thing.

				float answertc;
				steps = 0;
				int lev = ceil(log(NumberofDiamonds)/log(2));
				//Sorting the Elements.
				//Iteration over the activity store available with us .
					answertc = expecteddiamondvalue(0,NumberofDiamonds-1,lev);	
				/*for ( int i = 0;i < activitystore.size()+1;i++) {
					cout<<"Max t"<<i<<"   "<<max2[i];
				}*/
				cout<<"Steps :" <<steps;
				printf("%f\n",answertc);

//				memset(max2, 0, sizeof(float)*2000*2000);
				for(int i=0;i<NumberofDiamonds;i++) {
					cout<<"   i"<<used[i]<<endl;
				}
				memset(used, 0, sizeof(int)*2000);
				free(diamonds);
}

		//				g_fo.PrintUint(answertc, '\n');
				////cout<<"final answer  : "<<a<<"After division by :"<<divis<<endl;
/*
				for (int r = 0; r < NumberofDiamonds;r++) {
					free(max2[r]);
					free(used[r]);
				}
				free(max2);
				free(used);*/
		g_fo.Flush();
		return 0;
}
Example #3
0
int main() {
	char line[80];
	FastOutput output;
	int nCases;
	scanf("%d\n", &nCases);
	//gets(line);
	//sscanf(line, "%d\n", &nCases);

	for(int caseNum=1; caseNum<=nCases;caseNum++) {
		int length; 
		scanf("%d\n", &length);
		//gets(line);
		//sscanf(line, "%d\n", &length);

		nItems = 0;
		Subset subsets[length+100];//not technically correct?
		mySubsets = subsets;

		for(int i=0;i<length;i++) {

			char *s1 = new char[21]{'\0'};
			char *s2 = new char[21]{'\0'};

			scanf("%s %s\n", s1,s2);
			//gets(line);
			//sscanf(line, "%s %s\n", s1,s2);
			int index1 = trie.insert(s1);
			int index2 = trie.insert(s2);
			
			//printf ("%d %d\n", index1, index2);
			Union(index1,index2);

			output.PrintUint(subsets[find(index1)].total,'\n');
		}
		if (caseNum < nCases) {
			trie.reset();
		}
	}
		
	return 0;
}
Example #4
0
int main() {
	readAll();
	//printf ("Done = %s\n", A[arrayIndex+1000]);
	//return 0;
	clearHashes.reserve(MAX_FRIENDS);
	int nCases; 
	sscanf(A[arrayIndex++],"%d",&nCases);

	for(int caseNum=1; caseNum<=nCases;caseNum++) {
		int length; sscanf(A[arrayIndex++],"%d",&length);
		newIndex = 0;

		for(int i=0;i<length+10;i++) {
			subsets[i].parent=i;
			subsets[i].total=1;
		}
		for(int i=0;i<length;i++) {
			int index1 = getNewIndex();
			int index2 = getNewIndex();
			//printf("%d %d\n",index1, index2);
			
			Union(index1,index2);
			output.PrintUint(subsets[find(index1)].total,'\n');
		}
		#ifndef UNORDERED_MAP
		if (caseNum < nCases) {
			//reset
			for(auto &x:clearHashes) {
				myTable[x].clear();
			}
		}
		#endif
	}
	
	return 0;
}
Example #5
0
int main() {
  cin.sync_with_stdio(0);
 
  vector<int> primes;
  for (int i=2; i<=100; ++i) {
    bool ok = true;
    for (int j=2; j<i; ++j) {
      if (i % j == 0) {
        ok = false;
      }
    }
    if (ok) {
      primes.push_back(i);
    }
  }
  int nprimes = primes.size();
 
  static int cnt[100001][25];
  ZERO(cnt[0]);
 
  FastInput fin;
  FastOutput fout;
  int n = fin.readuint();
  for (int i=1; i<=n; ++i) {
    memcpy(cnt[i], cnt[i-1], sizeof cnt[i]);
    int x = fin.readuint();
    for (int j=0; j<nprimes; ++j) {
      while (x % primes[j] == 0) {
        x /= primes[j];
        ++cnt[i][j];
      }
    }
  }
 
  int q = fin.readuint();
  repeat (q) {
    int l = fin.readuint(), r = fin.readuint(), mod = fin.readuint();
    unsigned result = mod > 1 ? 1 : 0;
 
    static vector<pair<int, int> > entries; entries.clear();
    for (int a=0; a<nprimes; ++a) {
      int n = cnt[r][a] - cnt[l-1][a];
      if (n > 0) {
        entries.push_back(make_pair(n, primes[a]));
      }
    }
 
    sort(ALL(entries), greater<pair<int, int> >());
    entries.push_back(make_pair(0, 1));
 
    unsigned a = 1;
    for (int i=0; i<(int)entries.size()-1; ++i) {
      a = maybe_mod(mult(a, entries[i].second), mod);
      unsigned now = entries[i].first - entries[i+1].first;
      if (now > 0) {
        result = maybe_mod(mult(result, modpow(a, now, mod)), mod);
      }
    }
 
    fout.writeuint(result);
    fout.putchar('\n');
  }
 
  return 0;
}
Example #6
0
 fo(i, m)
 {
     //cout<<ans[i]<<endl;
     g_fo.PrintUint(ans[i], '\n');        
 }