Exemple #1
0
bool dfs(string &s){
    e.insert(s);
    v.push_back(s);
    for(multimap<string,string>::iterator it=h.lower_bound(s); 
            it!=h.end()&&it->first==s; ++it){
        if(e.find(it->second) != e.end()){
            continue;
        }
        map<string, int>::iterator mi = r.find(it->second);
        if(mi != r.end()){
            /*
            v.push_back(it->second);
            reverse(v.begin(), v.end());
            for(vector<string>::iterator vi=v.begin(); vi!=v.end(); vi++){
                cout<<*vi<<" ";
            }
            cout<<endl;
            */
            if(--mi->second<=0){
                r.erase(mi);
            }
            return true;
        } else if(dfs(it->second)){
            return true;
        }
    }
    v.pop_back();
    return false;
}
Exemple #2
0
int main()
{
	#ifdef LOCAL
		freopen(fn".in", "r", stdin);
		freopen(fn".out", "w", stdout);
	#endif
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		v.pb(i);
	ll maxx = -inf;
	do
	{
		ll ans = get();
		maxx = max(maxx, ans);
		s.insert(mp(ans, v));
	} while(next_permutation(v.begin(), v.end()));
	/*
	for (auto i = s.lower_bound(maxx); i != end(s); i++)
	{
		vector <int> t = i -> s;
		for (int i = 0; i < n; i++)
			printf("%d ", t[i]);
		puts("");
	}
	*/
	auto it = s.lower_bound(maxx);
	int t = 1;
	for (; it != end(s) && t < m; it++, t++);
	v = it -> s;
	for (int i = 0; i < n; i++)
		printf("%d ", v[i]);
}
Exemple #3
0
void printmultimap1(multimap <string, string> &authors)
{
	typedef multimap <string, string>::iterator iters;
	iters iterb = authors.lower_bound("Barth, John");//指向关键字的第一个数据
	iters itere = authors.upper_bound("Barth, John");//最后一个的下一个数据
	while (iterb!=itere)
	{
		cout << iterb->first << "--->" << iterb->second << endl;
		++iterb;
	}
}
Exemple #4
0
vector<string> TelephoneDirectory::find_entries(int number) 
{
   multimap<int, string>::iterator lower 
      = inverse_database.lower_bound(number);
   multimap<int, string>::iterator upper 
      = inverse_database.upper_bound(number);
   vector<string> result;
   
   for (multimap<int, string>::iterator pos = lower; 
        pos != upper; pos++)
      result.push_back(pos->second);
   return result;
}
Exemple #5
0
bool AlreadyHave(multimap<string, string> &mulMap,
                 const pair<string, string> &searchItem)
{
    multimap<string, string>::iterator begin = mulMap.lower_bound(searchItem.first);
    multimap<string, string>::iterator end = mulMap.upper_bound(searchItem.first);
    while(begin != end){
//        cout<<begin->second<<begin->first;
        if(begin->second == searchItem.second)
            return true;
        ++begin;
    }
    return false;
}
Exemple #6
0
void traceback(int key){
	multimap<int,int>::iterator first,last;
	printf("%d", key);
	
	first = edge.lower_bound(key);
	last = edge.upper_bound(key);
			
	for(;first != last; first++){
		printf(" (");
		traceback(first->second);
		printf(")");
	}
		
}
Exemple #7
0
void CfgToDotImpl::processNodes(SgNode* top) {
  if (nodesPrinted.find(top) != nodesPrinted.end()) return;
  nodesPrinted.insert(top);
  o << "subgraph cluster_" << uintptr_t(top) << " {" << endl;
  o << "style=invis;" << endl;
  for (multimap<SgNode*, CFGNode>::const_iterator it = exploredNodes.lower_bound(top);
       it != exploredNodes.upper_bound(top); ++it) {
    printNodePlusEdges(o, it->second);
  }
  vector<SgNode*> children = top->get_traversalSuccessorContainer();
  for (unsigned int i = 0; i < children.size(); ++i) {
    if (children[i]) {
      processNodes(children[i]);
    }
  }
  o << "}" << endl;
}
	int countRangeSum(vector<int>& nums, int lower, int upper)
	{
		_hash.clear(); _prefix.clear();
		_prefix.push_back(0);
		for (int i = 0, sz = nums.size(); i < sz; i++)
		{
			_prefix.push_back(_prefix.back() + nums[i]);
			_hash.insert(make_pair(_prefix.back(), i + 1));
		}
		int ret = 0;
		for (int i = 0, sz = _prefix.size(); i < sz; i++)
		{
			int64_t hoge = _prefix[i];
			for (auto it = _hash.lower_bound(hoge + lower);
				it != _hash.end() && it -> first <= hoge + upper; it++ )
				if (it -> second > i)
					ret++;
		}
		return ret;
	}
Exemple #9
0
static CRF_State
crfstate(const vector<Token> &vt, int i)
{
  CRF_State sample;

  string str = vt[i].str;
  //  string str = normalize(vt[i].str);

  sample.label = vt[i].pos;

  sample.add_feature("W0_" + vt[i].str);

  sample.add_feature("NW0_" + normalize(str));

  string prestr = "BOS";
  if (i > 0) prestr = vt[i-1].str;
  //  if (i > 0) prestr = normalize(vt[i-1].str);

  string prestr2 = "BOS";
  if (i > 1) prestr2 = vt[i-2].str;
  //  if (i > 1) prestr2 = normalize(vt[i-2].str);

  string poststr = "EOS";
  if (i < (int)vt.size()-1) poststr = vt[i+1].str;
  //  if (i < (int)vt.size()-1) poststr = normalize(vt[i+1].str);

  string poststr2 = "EOS";
  if (i < (int)vt.size()-2) poststr2 = vt[i+2].str;
  //  if (i < (int)vt.size()-2) poststr2 = normalize(vt[i+2].str);


  sample.add_feature("W-1_" + prestr);
  sample.add_feature("W+1_" + poststr);

  sample.add_feature("W-2_" + prestr2);
  sample.add_feature("W+2_" + poststr2);

  sample.add_feature("W-10_" + prestr + "_" + str);
  sample.add_feature("W0+1_" + str  + "_" + poststr);
  sample.add_feature("W-1+1_" + prestr  + "_" + poststr);

  //sample.add_feature("W-10+1_" + prestr  + "_" + str + "_" + poststr);

  //  sample.add_feature("W-2-1_" + prestr2  + "_" + prestr);
  //  sample.add_feature("W+1+2_" + poststr  + "_" + poststr2);

  // train = 10000 no effect
  //  if (i > 0 && prestr.size() >= 3)                
  //    sample.add_feature("W-1S_" + prestr.substr(prestr.size()-3));
  //  if (i < (int)vt.size()-1 && poststr.size() >= 3) 
  //    sample.add_feature("W+1S_" + poststr.substr(poststr.size()-3));

  // sentence type
  //  sample.add_feature("ST_" + vt[vt.size()-1].str);

  for (size_t j = 1; j <= 10; j++) {
    char buf[1000];
    //    if (str.size() > j+1) {
    if (str.size() >= j) {
      sprintf(buf, "SUF%d_%s", (int)j, str.substr(str.size() - j).c_str());
      sample.add_feature(buf);
    }
    //    if (str.size() > j+1) {
    if (str.size() >= j) {
      sprintf(buf, "PRE%d_%s", (int)j, str.substr(0, j).c_str());
      sample.add_feature(buf);
    }
  }
  
  for (size_t j = 0; j < str.size(); j++) {
    if (isdigit(str[j])) {
      sample.add_feature("CTN_NUM");
      break;
    }
  }
  for (size_t j = 0; j < str.size(); j++) {
    if (isupper(str[j])) {
      sample.add_feature("CTN_UPP");
      break;
    }
  }
  for (size_t j = 0; j < str.size(); j++) {
    if (str[j] == '-') {
      sample.add_feature("CTN_HPN");
      break;
    }
  }
  bool allupper = true;
  for (size_t j = 0; j < str.size(); j++) {
    if (!isupper(str[j])) {
      allupper = false;
      break;
    }
  }
  if (allupper) sample.add_feature("ALL_UPP");

  if (WNdic.size() > 0) {
    const string n = normalize(str);
    for (map<string, string>::const_iterator i = WNdic.lower_bound(n); i != WNdic.upper_bound(n); i++) {
      sample.add_feature("WN_" + i->second);
    }
  }
  //  for (int j = 0; j < vt.size(); j++)
  //    cout << vt[j].str << " ";
  //  cout << endl;
  //  cout << i << endl;

  //  cout << sample.label << "\t";
  //  for (vector<string>::const_iterator j = sample.features.begin(); j != sample.features.end(); j++) {
  //      cout << *j << " ";
  //  }
  //  cout << endl;
  
  return sample;
}