Example #1
0
int main()
{
  ull prod, i, j, T, N;

  for(i=999; i>99; i--)
  for(j=i; j>99; j--)
  {
    prod = i*j;
    if (is_palin(prod))
    {
      palins.insert(prod);
    }
  }

  cin >> T;
  for(i=0; i < T; i++)
  {
    cin >> N;
    si = palins.upper_bound(N);
    si--;
    cout << *si << endl;
  }

  return 0;
}  
Example #2
0
int run_test(bool mainProcess, const set<int> &case_set, const string command) {
    int cases = 0, passed = 0;
    while (true) {
        if (next_line().find("--") != 0)
            break;
        vector<string> roads;
        from_stream(roads);
        next_line();
        string __answer;
        from_stream(__answer);

        cases++;
        if (case_set.size() > 0 && case_set.find(cases - 1) == case_set.end())
            continue;

        cout << "  Testcase #" << cases - 1 << " ... ";
        if ( do_test(roads, __answer)) {
            passed++;
        }
    }
    if (mainProcess) {
        cout << endl << "Passed : " << passed << "/" << cases << " cases" << endl;
        int T = time(NULL) - 1395514835;
        double PT = T / 60.0, TT = 75.0;
        cout << "Time   : " << T / 60 << " minutes " << T % 60 << " secs" << endl;
        cout << "Score  : " << 250 * (0.3 + (0.7 * TT * TT) / (10.0 * PT * PT + TT * TT)) << " points" << endl;
    }
    return 0;
}
Example #3
0
void sol(string s, string t){
  queue<string> Q;
  map<string, string> M;
  Q.push(s);
  M[s] = "";
  while (!Q.empty()){
    string a = Q.front();
    Q.pop();
    for (size_t i = 0; i < a.size(); i++){
      string b = a;
      for (size_t ch = 'a'; ch <= 'z'; ch++){
        b[i] = ch;
        if (dict.find(b) == dict.end()){
          continue;
        }
      //  cout << a << "=>" << b << endl;
        if (M.find(b) != M.end()){
          continue;
        }
       // cout << "add" << endl;
        M.insert(make_pair(b, a));
        if (b == t){
          output(s, t, M);
          return;
        }
        Q.push(b);
      }
    }
  }
  cout << "No solution." << endl;
}
bool isInside(int y) {
	set< pair<bool, pii> >::iterator lb = segments.lower_bound(make_pair(START, make_pair(y, -oo)));
	if (lb != segments.end() && lb->first == START && lb->second.first == y) return true;
	lb = segments.lower_bound(make_pair(END, make_pair(-y, -oo)));
	if (lb != segments.end() && lb->first == END && -lb->second.first <= y && -lb->second.second >= y) return true;
	return false;
}
void analyzeHits (const set <vector <bool> >& hits, const set <string>& list) {
	set <string> temp;
	for (set <vector <bool> >::iterator it=hits.begin(); it!=hits.end(); it++)
		temp.insert(bool2seq(*it));
		
	return analyzeHits(temp, list);
}
int main()
{
	int i,j;
	while(EOF!=scanf("%d",&n))
	{
		q.clear();

		for(i=0;i<n;i++)
			scanf("%d %d",&x[i],&y[i]);

		for(i=0;i<n;i++)
			for(j=i+1;j<n;j++)
			{
				tmp=double(y[j]-y[i])/double(x[j]-x[i]);
			    if(x[i]==x[j])
					q.insert(10000);
				else
					q.insert(tmp);
			}

	
		printf("%d\n",q.size());

	}
	return 0;
}
Example #7
0
void dfs(string cur, int len) {
    // cout << "dfs(" << cur << ", " << len << ")\n";

    if (len > best_len) {
        best_len = len;
        string s = cur;
        out.clear();
        while (s != init) {
            out.push_back(s);
            s = previous[s];
        }
        out.push_back(init);
    }

    for (edge e : graph[cur]) {
        if (in_stack.find(e.end) == in_stack.end() and colors[e.color] >= e.quant) {
            in_stack.insert(e.end);
            colors[e.color] -= e.quant;
            previous[e.end] = cur;

            dfs(e.end, len + 1);

            colors[e.color] += e.quant;
            in_stack.erase(e.end);
        }
    }
}
Example #8
0
void addPreviouslySeenAds(unsigned int MAX, int cat, int user, map<int,User*> &userMap, map<int,int> &adToCat, set<int> &enabledAds, vector<int> &ads) {
  if(ads.size() >= MAX)
    return;

  User *u = userMap[user];
  vector<Impression> &impressions = u->impressions;
  
  set<int> seen;
  for(vector<int>::iterator it = ads.begin(); it != ads.end(); ++it) {	
    seen.insert(*it);
  }

  for(vector<Impression>::reverse_iterator it = impressions.rbegin(); it != impressions.rend(); ++it) {	
    Impression &i = *it;
    int a = i.adID;
    if(adToCat[a] != cat)
      continue; // Wrong category.
    if(seen.find(a) != seen.end())
      continue; // Already added
    if(enabledAds.find(a) == enabledAds.end())
      continue;
    ads.push_back(a);
    seen.insert(a);
    if(ads.size() >= MAX)
      break;
  }
}
int main()
{
    scanf("%lld%lld",&n,&k);
    n2=n;
    while(--k>0) {
        scanf("%lld",&a);
        v.push_back(a);
    }
    scanf("%lld",&a);
    n=NWD(n,a);
    for(int i=0; i<v.size(); i++)s.insert(NWD(v[i],n));
    for(long long int i=1; i<=sqrt(n); i++)if(n%i==0)
        {
            a = i;
            found = true;
            for(it=s.begin(); it!=s.end(); it++)if((*it)%a==0) {
                    found = false;
                    break;
                }
            if(found)
            {
                printf("%lld",n2/a);
                return 0;
            }
            a = n/i;
            found = true;
            for(it=s.begin(); it!=s.end(); it++)if((*it)%a==0) {
                    found = false;
                    break;
                }
            if(found)wynik=n2/a;
        }
    printf("%lld",wynik);
    return 0;
}
void remove_covering_region(string /*event*/, map<string,EvTRel *> &tr_map, const SS &sr, Region &partition, const SS &/*state_space*/,
                            list<Region *> &localRegs,set<string> localEvs,map<string,int> &flow_map)
{
    list<Region *>::iterator it;
    for(it=localRegs.begin(); it!=localRegs.end(); ++it)
    {
        if (sr <= (*it)->sup())
        {
            break;
        }
    }
    if (it != localRegs.end())
    {
        SS rsup = (*it)->sup();
        partition.additive_substraction(**it);
        localRegs.erase(it);
        set<string>::const_iterator ite;
        for(ite=localEvs.begin(); ite!=localEvs.end(); ++ite)
        {
            if (tr_map[*ite]->get_er() <= rsup)
            {
                flow_map[*ite]++;
            }
            if (tr_map[*ite]->get_sr() <= rsup)
            {
                flow_map[*ite]--;
            }
        }
    }
}
Example #11
0
void Piece::addMoves(
		Location current,
		Board& board,
		set<Location>& moves,
		int rowDiff,
		int colDiff) const
{
	Location next = Location(current.row() + rowDiff, current.column() + colDiff);
	while(true)
	{
		if (!next.isValid())
			break;
		if (board.at(next) != NULL)
		{
			if (board.at(next)->color() != this->color())
			{
				moves.insert(next);
			}
			break;
		}
		else
		{
			moves.insert(next);
		}
		next = Location(next.row() + rowDiff, next.column() + colDiff);
	}
}
Example #12
0
void dfs(string cur, set<int> rem, int k, int d = 0)
{
  if (d + abs(cur.size() - s2.size()) >= ans)
  {
    return;
  }
  if (cur == s2)
  {
    ans = d;
    return;
  }
  if (vis.find({cur, k}) == vis.end())
  {
    return;
  }
  vis.insert({cur, k});
  string tmp;
  if (k > 0 && k <= cur.size())
  {
    dfs(cur, rem, k -1, d+1);
    tmp = cur;
    tmp.erase(k-1);
    r.insert(k-1);
  }
  if (k >= 0 && k < cur.size())
  {
    dfs(cur, rem, k + 1, d + 1);
  }
}
Example #13
0
int main ()
{
    while (cin >> str, str != "#") {
        ans.clear();
        string tmp = str;
        dfs(tmp, 0, 0);
        int s = ans.size();
        cout << s << endl;

        int k = 0;
        if (0 < s && s <= 10) {
            for (auto i : ans) {
                cout << i << endl;
            }
        } else if (s > 10) {
            int k = 0;
            for (auto i : ans) {
                if (k == 5) break;
                cout << i << endl;
                k++;
            }
            auto ite = ans.end(); ite--; ite--; ite--; ite--; ite--;
            k = 0;
            while (k++ < 5) {
                cout << *ite << endl;
                ite++;
            }
        }
    }

    return 0;
}
Example #14
0
	void unregisterObserver(Observer *deleteObserver) {
		set <Observer*>:: iterator it = observers.find(deleteObserver);
		if (it != observers.end()) {
			observers.erase(it);
		}
		cout << "Observer Unregistered Successfully!" << endl;
	}
void output(set<P> s) {
    for(set<P>::iterator iter = s.begin();
            iter != s.end(); ++iter) {
        disp(*iter);
    }
    puts("");
}
Example #16
0
double n_2(set& s) {
    double min = euclidean_distance(s[0], s[1]);
    for (std::size_t i = 0; i < s.size() - 1; ++i)
        for (std::size_t j = i + 1; j < s.size(); ++j)
            min = std::min(min, euclidean_distance(s[i], s[j]));
    return min;
}
Example #17
0
// we now work with names instead of Genome*s to avoid expensive openGenome
// function
static bool spanningRecursive(const Alignment* alignment,
                              const string& genome,
                              set<const Genome*>& outputSet,
                              set<string>& outputNames,
                              bool below = false)
{
    bool above = false;
    if (outputNames.find(genome) != outputNames.end())
    {
        below = true;
        above = true;
    }
    vector<string> childs = alignment->getChildNames(genome);
    for (hal_size_t i = 0; i < childs.size(); ++i)
    {
        bool childAbove = spanningRecursive(alignment, childs[i], outputSet,
                                            outputNames, below);
        above = above || childAbove;
    }

    if (above && below)
    {
        outputSet.insert(alignment->openGenome(genome));
        outputNames.insert(genome);
    }
    return above;
}
Example #18
0
int findMutationDistance(string s, string e, vector < string > b) {
	start = s;
	queue<pair<string,lli>  > q ;
	q.push({e,0});
	for(auto x:b){
		availableGenes.insert(x);
	}
	string genes("ACTG");
	while(!q.empty()){
		pair<string,lli> processing(q.front());
		if(processing.first == s){
			return processing.second;
		}
		if(getDifference(processing.first) == 1){
			return processing.second+1;
		}
		for(int i(0);i<8;i++){
			for(auto x:genes){
				string current(processing.first);
				current[i] = x;
				if(availableGenes.find(current) != availableGenes.end()){
					q.push({current,processing.second+1});
					availableGenes.erase(current);
				}
			}
		}
		q.pop();
	}
	return -1;
}
void dodajDanie(set<Danie> & danie, vector<int> dania[]) {
	dania[nDan].clear();
	for(set<Danie>::iterator iter = danie.begin(); iter != danie.end(); iter++) {
		dania[nDan].push_back(iter->wartosc);
	}
	nDan++;
}
Example #20
0
File: C.cpp Project: gzgreg/ACM
bool dp(string s, int idx, vector<int> memo) {
	if(idx == s.size()) {
		return true;
	}
	if(memo[idx] != -1) {
		if(memo[idx] == 1) return true;
		return false;
	}
	bool ret = false;

	if(idx <= s.size() - 2 && elems.find(s.substr(idx, 2)) != elems.end()) {
		ret = dp(s, idx + 2, memo);
	}

	if(ret){
		memo[idx] = 1;
		return ret;
	} 
	if(elems.find(s.substr(idx, 1)) != elems.end()) {
		ret = dp(s, idx + 1, memo);
	}
	if(ret) {
		memo[idx] = 1;
	} else {
		memo[idx] = 0;
	}
	return ret;
}
Example #21
0
void processGroup (Group& group, set<string>& refs)
{
    int valid_count = 1;
    GroupKey key_a;
    GroupKey key_b;
    GroupRange range_a;
    GroupRange range_b;

    for (set<string>::iterator reference = refs.begin();
         reference != refs.end(); ++reference )
    {
        key_a.refID = *reference;
        key_b.refID = *reference;

        key_a.mateID = '1';
        key_b.mateID = '2';

        key_a.rev = true;
        key_b.rev = false;

        range_a = group.equal_range(key_a);
        range_b = group.equal_range(key_b);

        processGroupRange(range_a, range_b, valid_count);

        key_a.rev = false;
        key_b.rev = true;

        range_a = group.equal_range(key_a);
        range_b = group.equal_range(key_b);

        processGroupRange(range_a, range_b, valid_count);
    }
}
Example #22
0
void CMaxmatch::Generate_Segmentation_Matrix(const char* SentBuf, set<string>& locCSWords_Set, vector<string>& TokenCS_v, unsigned int Max_Word_Length, bool SegMatrix[MAX_CLAUSE_LENGTH][MAX_CLAUSE_LENGTH], unsigned int& mLength)
{
	char sChar[3];
	int strLen = strlen(SentBuf);
	int rowtokenlength = 0;
	int coltokenlength = 0;
	string wordstr;
	sChar[2]=0;
	for(int forposit = 0; forposit < strLen; ){
		wordstr = "";
		for(int bacposit = 0; ((forposit + bacposit) < strLen) && (bacposit < (int)Max_Word_Length); ){
			sChar[0]=SentBuf[forposit + bacposit++];
			sChar[1]=0;	
			if(sChar[0] < 0 ){
				sChar[1]=SentBuf[forposit + bacposit++];
			}
			wordstr += sChar;
			if(locCSWords_Set.find(wordstr) != locCSWords_Set.end()){
				SegMatrix[rowtokenlength][coltokenlength] = true;;
			}
			coltokenlength++;
		}
		sChar[0]=SentBuf[forposit++];
		sChar[1]=0;	
		if(sChar[0] < 0 ){
			sChar[1]=SentBuf[forposit++];
		}
		TokenCS_v.push_back(sChar);
		rowtokenlength++;
		coltokenlength = rowtokenlength;
	}
	mLength = rowtokenlength;
}
Example #23
0
int solution(uint goal) {
    if (min_num.count(goal) == 1) {
        return (int) min_num.at(goal).size();
    } else {
        bool f = false;
        int result = INT32_MAX;
        multiset<uint> cur_set;
        int prev_sol;
        for (auto i = values.begin(); i != values.end(); i++) {
            if (goal - *i > goal) {
                continue;
            }
            prev_sol = solution(goal - *i);
            if (prev_sol == -1) {
                continue;
            }
            if (result > 1 + prev_sol) {
                f = true;
                result = 1 + prev_sol;
                cur_set = min_num.at(goal - *i);
                cur_set.insert(*i);
            }
        }
        min_num[goal] = cur_set;
        if (f) {
            return result;
        } else {
            return -1;
        }
    }
}
Example #24
0
    void operator()() {
#ifdef FAST_AND_FAT
        //! Performing feature transformation on a block results
        //! is about a factor of two speedup. This suggests moving
        //! feature storage from nodes to images. However, the
        //! change will make introduction of different node
        //! types (with different sized feature vectors) difficult.
        //! It also means that the metric functors would need to
        //! be passed a copy of the graph in addition to the nodes.
        for (set<unsigned>::const_iterator it = _imgIndxes.begin(); it != _imgIndxes.end(); ++it) {
            lock();
            map<unsigned, MatrixXf>::const_iterator ft = _imgFeatureData.find(*it);
            if (ft == _imgFeatureData.end()) {
                MatrixXf X(_Lt.cols(), _srcGraph[*it].numNodes());
                for (unsigned segId = 0; segId < _srcGraph[*it].numNodes(); segId++) {
                    X.col(segId) = _srcGraph[*it][segId].features;
                }
                ft = _imgFeatureData.insert(_imgFeatureData.end(), make_pair(*it, X));
            }
            unlock();

            const MatrixXf X = _Lt.triangularView<Eigen::Upper>() * ft->second;
            for (unsigned segId = 0; segId < _srcGraph[*it].numNodes(); segId++) {
                _negGraph[*it][segId].features = _posGraph[*it][segId].features = X.col(segId);
            }
        }
#else
        const TriangularView<MatrixXf, Eigen::Upper> Lt(_Lt);
        for (set<unsigned>::const_iterator it = _imgIndxes.begin(); it != _imgIndxes.end(); ++it) {
            for (unsigned segId = 0; segId < _srcGraph[*it].numNodes(); segId++) {
                _negGraph[*it][segId].features = _posGraph[*it][segId].features = Lt * _srcGraph[*it][segId].features;
            }
        }
#endif
    }
// ----------------------------------------------------------------------------
float * ofOpenALSoundPlayer::getSystemSpectrum(int bands){
	initSystemFFT(bands);
	systemBins.assign(systemBins.size(),0);
	if(players.empty()) return &systemBins[0];

	int signalSize = (bands-1)*2;
	if(int(systemWindowedSignal.size())!=signalSize){
		systemWindowedSignal.resize(signalSize);
	}
	systemWindowedSignal.assign(systemWindowedSignal.size(),0);

	set<ofOpenALSoundPlayer*>::iterator it;
	for(it=players.begin();it!=players.end();it++){
		if(!(*it)->getIsPlaying()) continue;
		float * buffer = (*it)->getCurrentBufferSum(signalSize);
		for(int i=0;i<signalSize;i++){
			systemWindowedSignal[i]+=buffer[i];
		}
	}

	float normalizer = 2. / windowSum;
	runWindow(systemWindowedSignal);
	kiss_fftr(systemFftCfg, &systemWindowedSignal[0], &systemCx_out[0]);
	for(int i= 0; i < bands; i++) {
		systemBins[i] += sqrtf(systemCx_out[i].r * systemCx_out[i].r + systemCx_out[i].i * systemCx_out[i].i) * normalizer;
	}
	return &systemBins[0];
}
//set<int> s;
int main(int argc,char* argv[])
{
  read;
  write;
  int n,a[3],b[3];
  lock l;
  scanf("%d",&n);
  for(int i = 0 ; i < 3 ; i++)
    scanf("%d",&a[i]);
  for(int i = 0 ; i < 3 ; i++)
    scanf("%d",&b[i]);
  
  for(int i = -2 ; i <= 2 ; i++ )
    for(int j = -2 ; j <= 2 ; j++)
      for(int k = -2 ; k <= 2 ; k++)
	{
	  l.a = (a[0]+n+i)%n,
	  l.b = (a[1]+n+j)%n,
	  l.c = (a[2]+n+k)%n;
	  s.insert(l);

	  l.a = (b[0]+n+i)%n;
	  l.b = (b[1]+n+j)%n;
	  l.c = (b[2]+n+k)%n;
	  s.insert(l);
	}

  printf("%d\n",(int)s.size());
  return 0;
}
int main() {
    ///check for 0 or -1 if input not specified
    #ifdef mamun
//        READ("in.txt");
//        WRITE("out.txt");
    #endif // mamun
//    ios_base::sync_with_stdio(0);cin.tie(0);
    while(~getI(n))
    {
        st.clear();
//        st.insert(0);
//        rep(i,25)st.insert(i);
        rep(i,n){
            getI(m);
            st.insert(m);
        }
        int cnt = 1;
        while(st.size() != 25)
        {
            while(st.count(cnt))cnt++;
            st.insert(cnt);
        }
        int ans = 0;
        int lst = 0;
        for(auto it: st)
        {
            ans += (it-lst-1);
            lst = it;
        }
        printf("%d\n",ans);
    }
void f(int i, const string& last){
    if(vis[i].count(last)) return;
    vis[i].insert(last);
    
    if(i - 2 >= 4){
        string tmp = "";
        tmp += s[i-1];
        tmp += s[i];
        if(tmp != last){
            ss.insert(tmp);
            f(i-2, tmp);
        }
    }
    if(i - 3 >= 4){
        string tmp = "";
        tmp += s[i-2];
        tmp += s[i-1];
        tmp += s[i];
        if(tmp != last){
            ss.insert(tmp);

            f(i-3, tmp);
        }
    }
}
// Load one motif's binding.
int loadone(GBMap& onebind, const string& motif, const set<string>& genset, const string& folder)
{
	string fBind = folder + "/" + motif + ".func";
	ifstream hBind(fBind.data());
	if(!hBind)
	{
		cerr << "Can't open " << fBind << endl;
		return 1;
	}
	while(hBind.good())
	{
		string strLn;
		getline(hBind, strLn);
		if(strLn == "")
			continue;
		istringstream gStrm(strLn);
		string gene;
		int nb;
		gStrm >> gene >> nb;
		str2upper(gene);
		if(genset.find(gene) == genset.end())
			continue;
		VGB vgb;
		for(int j = 0; j < nb; j++)
		{
			string site;
			gStrm >> site;
			vgb.e.push_back(extrbnd(site));
		}
		onebind.e[gene] = vgb;
	}
	return 0;
}
Example #30
0
vector<LineCounter> LoadDoc(ifstream& read, string fun, set<string> dic) //map function?
{
    vector<LineCounter> list;
    int count = 1;
    LineCounter temporary;
    while (getline(read, fun)) //So every line is 1 string now
    {
        fun = LowerandStuff(fun);


        stringstream party;

        party << fun;
        string word;
        while (party>>word)
        {
            const bool is_in = dic.find(word) != dic.end();
            if(is_in== false)//How do you say if it's not in a set?
            {
                temporary.setWord(word);
                temporary.setNumber(count);

                list.push_back(temporary);
            }

        }


        count++;
    }

    return list;

}