当前位置: 首页>>代码示例>>C++>>正文


C++ set::insert方法代码示例

本文整理汇总了C++中set::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ set::insert方法的具体用法?C++ set::insert怎么用?C++ set::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在set的用法示例。


在下文中一共展示了set::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void update(set<int>&s , int pos, int col){
    if (a[pos]== col){
        return ; 
    }
    if (pos == 1){
        if (a[pos] == a[pos+1]){
            s.insert(2) ; a[pos] = col ; return ; 
        }
        else{
            if (col == a[pos+1]){
                s.insert(1) ; s.erase(2) ; a[pos] = col ; return ; 
            }
        }
    }
    if (a[pos-1] == a[pos+1]){
        if (a[pos]==a[pos+1]){
            s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ; 
        }
        if (a[pos]!=a[pos+1]){
            
            if (col == a[pos+1]){
                s.erase(pos) ; s.erase(pos+1) ; a[pos] = col ; return ; 
            }
            
        }
    }
    else {
        if (a[pos]==a[pos+1]){
            if (col != a[pos-1]){
                s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ; 
            }
            if (col == a[pos-1]){
                s.insert(pos+1) ;s.erase(pos) ; a[pos] = col ; return ;  
            }
        }
        if (a[pos] == a[pos-1]){
            if (col == a[pos+1]){
                s.insert(pos) ; s.erase(pos+1) ; a[pos] = col ; return ; 
            }
            else{
                s.insert(pos) ; s.insert(pos+1) ; a[pos] = col ; return ; 
            }
        }
        if ((a[pos]!= a[pos-1]) && (a[pos]!= a[pos+1])){
            if (col == a[pos-1]){
                s.erase(pos) ; s.insert(pos+1) ; a[pos] = col ; return ; 
            }
            if (col == a[pos+1]){
                s.erase(pos+1) ; s.insert(pos) ; a[pos] = col ; return ; 
            }
        }
    }
}
开发者ID:rajiv256,项目名称:CP,代码行数:53,代码来源:paintbox.cpp

示例2: main

int main() {
	const bool debug = false;
	int i, j, k;
	P bg, nd, t;
	while(~scanf("%d%d%d%d", &x1, &y1, &x2, &y2)) {
		if(x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0)break;
		scanf("%d", &n);

		x.clear();x.insert(x1);x.insert(x2);
		y.clear();y.insert(y1);y.insert(y2);

		for(i = 0; i < n; i++) {
			b[i].init();
			x.insert(b[i].x1);
			x.insert(b[i].x2);
			y.insert(b[i].y1);
			y.insert(b[i].y2);
		}
		hx.clear();
		hy.clear();

		//对x离散化
		for(si = x.begin(), mx = 2; si != x.end(); hx[*si++] = mx, mx+=2) ;

		//对y离散化
		for(si = y.begin(), my = 2; si != y.end(); hy[*si++] = my, my+=2);
		//初始化
		for(j = 0; j < 4; ++j){
			for(i = 0; i < mx; ++i){
				if(!j)fill(m[i], m[i] + my, 0);
				fill(v[j][i], v[j][i] + my, false);
				fill(s[j][i], s[j][i] + my, inf);
			}
		}

		//填充矩阵,填充为1
		for(i = 0; i < n; i++) {
			int xuper = hx[b[i].x2];
			int yuper = hy[b[i].y2];
			//填充上下边界
			for(j = hx[b[i].x1]; j <= xuper; j++){
				m[j][hy[b[i].y1]]=m[j][hy[b[i].y2]]=1;
			}
			//填充左右边界
			for(k = hy[b[i].y1]; k <= yuper; k++){
				m[hx[b[i].x1]][k]=m[hx[b[i].x2]][k]=1;
			}
			//填充矩阵内部
			for(j = hx[b[i].x1] + 1; j < xuper; j++) {
				for(k = hy[b[i].y1] + 1; k < yuper; k++) {
					m[j][k]=2;
				}
			}
		}


		//此路不同,标记为2
		for(i=1;i<mx-1;i++){
			for(j=1;j<my-1;j++){
				if(m[i-1][j]&&m[i][j-1]&&m[i+1][j]&&m[i][j+1])
					m[i][j]=2;
			}
		}

		if(debug) {
			puts("---- stp ----");
			for(i = 0; i < mx; i++) {
				for(j = 0; j < my; j++) {
					printf(" %2d",m[i][j]);
				}
				puts("");
			}
			puts("---- stp ----\n\n");
		}


		while(!que.empty())que.pop();

		nd.x = hx[x2];
		nd.y = hy[y2];

		bg.x = hx[x1];
		bg.y = hy[y1];

		bg.stp = 0;
		//分别标记出发点的四个方向,并入‡队
		for(i = 0; i < 4; i++) {
			bg.d = i;
			v[i][bg.x][bg.y] = true;
			s[i][bg.x][bg.y] = 0;
			que.push(bg);
		}

		int ndnum=0;

		while(!que.empty()) {

			bg = que.top();que.pop();

			//由于是优先搜索,所以只要到达就一定是最优的
//.........这里部分代码省略.........
开发者ID:chyyuu,项目名称:ACM,代码行数:101,代码来源:HUD_4444_03.cpp

示例3: AddTimeData

void AddTimeData(const CNetAddr& ip, int64_t nTime)
{
    int64_t nOffsetSample = nTime - GetTime();

    LOCK(cs_nTimeOffset);
    // Ignore duplicates
    static set<CNetAddr> setKnown;
    if (!setKnown.insert(ip).second)
        return;

    // Add data
    static CMedianFilter<int64_t> vTimeOffsets(200,0);
    vTimeOffsets.input(nOffsetSample);
    LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60);

    // There is a known issue here (see issue #4521):
    //
    // - The structure vTimeOffsets contains up to 200 elements, after which
    // any new element added to it will not increase its size, replacing the
    // oldest element.
    //
    // - The condition to update nTimeOffset includes checking whether the
    // number of elements in vTimeOffsets is odd, which will never happen after
    // there are 200 elements.
    //
    // But in this case the 'bug' is protective against some attacks, and may
    // actually explain why we've never seen attacks which manipulate the
    // clock offset.
    //
    // So we should hold off on fixing this and clean it up as part of
    // a timing cleanup that strengthens it in a number of other ways.
    //
    if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1)
    {
        int64_t nMedian = vTimeOffsets.median();
        std::vector<int64_t> vSorted = vTimeOffsets.sorted();
        // Only let other nodes change our time by so much
        if (abs64(nMedian) < 70 * 60)
        {
            nTimeOffset = nMedian;
        }
        else
        {
            nTimeOffset = 0;

            static bool fDone;
            if (!fDone)
            {
                // If nobody has a time different than ours but within 5 minutes of ours, give a warning
                bool fMatch = false;
                BOOST_FOREACH(int64_t nOffset, vSorted)
                    if (nOffset != 0 && abs64(nOffset) < 5 * 60)
                        fMatch = true;

                if (!fMatch)
                {
                    fDone = true;
                    string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong CryptoSpots will not work properly.");
                    strMiscWarning = strMessage;
                    LogPrintf("*** %s\n", strMessage);
                    uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
                }
            }
        }
开发者ID:ssdpool,项目名称:cryptospot-changes,代码行数:64,代码来源:timedata.cpp

示例4: findUniqueWidgetTypes

void findUniqueWidgetTypes(fstream& stream, WidgetNode *root, set<string> &widgetTypes) {
	if(root->widgetType!="Gui" && root->widgetType!="root")
		widgetTypes.insert(root->widgetType);
	for(size_t i = 0; i < root->children.size(); i++)
		findUniqueWidgetTypes(stream, root->children[i], widgetTypes); 
}
开发者ID:AliSayed,项目名称:MoSync,代码行数:6,代码来源:main.cpp

示例5: CloneInnerLoop

void WorklessInstrument::CloneInnerLoop(Loop * pLoop, vector<BasicBlock *> & vecAdd, ValueToValueMapTy & VMap, set<BasicBlock *> & setCloned)
{
	Function * pFunction = pLoop->getHeader()->getParent();
	BasicBlock * pPreHeader = vecAdd[0];

	SmallVector<BasicBlock *, 4> ExitBlocks;
	pLoop->getExitBlocks(ExitBlocks);

	set<BasicBlock *> setExitBlocks;

	for(unsigned long i = 0; i < ExitBlocks.size(); i++)
	{
		setExitBlocks.insert(ExitBlocks[i]);
	}

	for(unsigned long i = 0; i < ExitBlocks.size(); i++ )
	{
		VMap[ExitBlocks[i]] = ExitBlocks[i];
	}

	vector<BasicBlock *> ToClone;
	vector<BasicBlock *> BeenCloned;

	
	//clone loop
	ToClone.push_back(pLoop->getHeader());

	while(ToClone.size()>0)
	{
		BasicBlock * pCurrent = ToClone.back();
		ToClone.pop_back();

		WeakVH & BBEntry = VMap[pCurrent];
		if (BBEntry)
		{
			continue;
		}

		BasicBlock * NewBB;
		BBEntry = NewBB = BasicBlock::Create(pCurrent->getContext(), "", pFunction);

		if(pCurrent->hasName())
		{
			NewBB->setName(pCurrent->getName() + ".CPI");
		}

		if(pCurrent->hasAddressTaken())
		{
			errs() << "hasAddressTaken branch\n" ;
			exit(0);
		}

		for(BasicBlock::const_iterator II = pCurrent->begin(); II != pCurrent->end(); ++II )
		{
			Instruction * NewInst = II->clone();
			if(II->hasName())
			{
				NewInst->setName(II->getName() + ".CPI");
			}
			VMap[II] = NewInst;
			NewBB->getInstList().push_back(NewInst);
		}

		const TerminatorInst *TI = pCurrent->getTerminator();
		for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
		{
			ToClone.push_back(TI->getSuccessor(i));
		}

		setCloned.insert(NewBB);
		BeenCloned.push_back(NewBB);
	}

	//remap value used inside loop
	vector<BasicBlock *>::iterator itVecBegin = BeenCloned.begin();
	vector<BasicBlock *>::iterator itVecEnd = BeenCloned.end();

	for(; itVecBegin != itVecEnd; itVecBegin ++)
	{
		for(BasicBlock::iterator II = (*itVecBegin)->begin(); II != (*itVecBegin)->end(); II ++ )
		{
			//II->dump();
			RemapInstruction(II, VMap);
		}
	}

	//add to the else if body
	BasicBlock * pElseBody = vecAdd[1];

	BasicBlock * pClonedHeader = cast<BasicBlock>(VMap[pLoop->getHeader()]);

	BranchInst::Create(pClonedHeader, pElseBody);

	//errs() << pPreHeader->getName() << "\n";
	for(BasicBlock::iterator II = pClonedHeader->begin(); II != pClonedHeader->end(); II ++ )
	{
		if(PHINode * pPHI = dyn_cast<PHINode>(II))
		{
			vector<int> vecToRemoved;
			for (unsigned i = 0, e = pPHI->getNumIncomingValues(); i != e; ++i) 
//.........这里部分代码省略.........
开发者ID:songlh,项目名称:LDoctor,代码行数:101,代码来源:WLInstrument.cpp

示例6: main

int main(){
	int n;
	scanf("%d", &n);
	gets(linha);
	
	for(int i = 0; i < n; ++i){
		gets(linha);
		int tam = strlen(linha);
		
		string aux = "";
		int prt = 0;
		while(prt < tam && aux != "void"){
			if(linha[prt] != ' ') aux += linha[prt];
			++prt;
		}
		
		aux = "";
		while(prt < tam && linha[prt] != '('){
			if(linha[prt] != ' ') aux += linha[prt];
			++prt;
		}
		
		Func funcao;
		funcao.name = aux;
		
		++prt;//pila o '('
		
		while(prt < tam && linha[prt] != ')'){
			aux = "";
			while(prt < tam && linha[prt] != ',' && linha[prt] != ')'){
				if(linha[prt] != ' ') aux += linha[prt];
				++prt;
			}
			++prt;
			
			if(aux != ""){
				Var var;
				var.type = aux;
				var.name = "";
				funcao.par.push_back(var);
			}
		}
		
		funcs.insert(funcao);
	}
	
//	for(set<Func>::iterator it = funcs.begin(); it != funcs.end(); ++it){
//		print(*it);
//	}
		
	int q;
	scanf("%d", &q);
	
	while(q--){
		scanf("%s %s", tipo, nome);	
		mapa[nome].push_back(tipo);	
	}
	scanf("%d", &q);
	gets(linha);
	
	while(q--){
		gets(linha);
		int prt = 0, tam = strlen(linha);
		string aux = "";
		
		while(prt < tam && linha[prt] != '('){
			if(linha[prt] != ' ') aux += linha[prt];
			++prt;
		}
		
		++prt;//pula '('
		Func funcao;
		funcao.name = aux;
		
		while(prt < tam && linha[prt] != ')'){
			aux = "";
			while(prt < tam && linha[prt] != ')' && linha[prt] != ','){
				if(linha[prt] != ' ') aux += linha[prt];
				++prt;
			}
			++prt;
			
			if(aux != ""){
				Var var;
				var.name = aux;
				var.type = "";
				funcao.par.push_back(var);
			}
		}
		
		int cont = 0;
		for(set<Func>::iterator it = funcs.begin(); it != funcs.end(); ++it){
			if(pode(*it, funcao)) ++cont;
		}
		printf( "%d\n", cont);
	}
}
开发者ID:mbfilho,项目名称:icpc,代码行数:97,代码来源:D+-+Programming+Language.cpp

示例7: getGrid

void getGrid()
{
	vector<pair<int, int> > C;
	int n;
	scanf("%d", &n);
	int minx = INT_MAX, maxx = INT_MIN;
	int miny = INT_MAX, maxy = INT_MIN;
	
	while (n--) 
	{
		int x, y;
		scanf("%d%d", &x, &y);
		C.push_back(make_pair(x, y));
		minx = min(minx, x);
		miny = min(miny, y);
		maxx = max(maxx, x);
		maxy = max(maxy, y);
	}
	
	for (int i = 0; i < C.size(); i++) {
		int x = C[i].first + (-minx);
		int y = C[i].second + (-miny);
		G[y][x] = 1;
	}
	
	int mnx = minx, mny = miny;
	maxx = maxx - minx;
	minx = 0;
	maxy = maxy - miny;
	miny = 0;

	for (int i = miny; i <= maxy; i++) {
		int  flag = 0;
		for (int j = minx; j <= maxx; j++) { 
			if (G[i][j])
				flag = 1;
			B[i][j] += flag; 
		}
	}

	for (int i = miny; i <= maxy; i++) {
		int  flag = 0;
		for (int j = maxx; j >= minx; j--) { 
			if (G[i][j])
				flag = 1;
			B[i][j] += flag; 
		}
	}

	for (int j = minx; j <= maxx; j++) {
		int  flag = 0;
		for (int i = maxy; i >= miny; i--) { 
			if (G[i][j])
				flag = 1;
			B[i][j] += flag; 
		}
	}

	for (int j = minx; j <= maxx; j++) {
		int  flag = 0;
		for (int i = miny; i <= maxy; i++) { 
			if (G[i][j])
				flag = 1;
			B[i][j] += flag; 
		}
	}

	for (int j = minx; j <= maxx; j++) {
		for (int i = miny; i <= maxy; i++) {
			if (B[i][j] == 4)
				G[i][j] = G[i][j] || 1;
		}
	}
	
	for (int i = maxy; i >= miny; i--) 
		for (int j = minx; j <= maxx; j++) 
			if (G[i][j]) 
				points.insert(make_pair(mnx+j,mny+i));
}
开发者ID:PeacefulAbhyasi,项目名称:Competitive-Programming,代码行数:79,代码来源:RandomPointsWithOptimallity.cpp

示例8: roundcnt

        int roundcnt(vector <int> tree, vector <int> A, vector <int> B)
        {
            n = tree.size() + 1; 
            blue.clear();
            for(int i = 0; i < n; i++) e[i].clear();
            for(int i = 1; i < n; i++)
            {
                e[i].push_back(tree[i - 1]);
                e[tree[i - 1]].push_back(i);
            }
            for(int i = 0; i < (int)B.size(); i++) blue.insert(B[i]);

            for(int i = 0; i < n; i++)
            {
                bool vis[100]; 
                queue<pair<int, int> > q;
                clr(vis, 0);
                vis[i] = 1;
                q.push(MP(i, 0));
                while(!q.empty())
                {
                    pair<int, int> tmp = q.front(); 
                    //if(i == 0) printf("%d\n", tmp.first);
                    q.pop();
                    if(blue.find(tmp.first) != blue.end())
                    {
                        d[i] = tmp.second;
                        break;
                    }
                    int u = tmp.first;
                    for(int j = 0; j < (int)e[u].size(); j++)
                    {
                        int v = e[u][j];
                        if(vis[v]) continue;
                        vis[v] = true;
                        q.push(MP(v, tmp.second + 1));
                    }
                }
            }
            //for(int i = 0; i < n; i++) printf("%d\n", d[i]);
            int ans = 1e8;
            for(int i = 0; i < (int)A.size(); i++)
            {
                bool vis[100]; 
                int val = 0;
                queue<pair<int, int> > q;
                clr(vis, 0);
                vis[A[i]] = 1;
                q.push(MP(A[i], 0));
                while(!q.empty())
                {
                    pair<int, int> tmp = q.front(); 
                    q.pop();
                    int u = tmp.first;
                    val = max(val, d[u]);
                    if(d[u] <= tmp.second)
                    {
                        continue;
                    }
                    for(int j = 0; j < (int)e[u].size(); j++)
                    {
                        int v = e[u][j];
                        if(vis[v]) continue;
                        vis[v] = true;
                        q.push(MP(v, tmp.second + 1));
                    }
                }
                ans = min(ans, val);
            }
            return ans;
        }
开发者ID:LTzycLT,项目名称:code,代码行数:71,代码来源:Treestrat.cpp

示例9: narrowDownDictionary

/*
 * Creates a new dictionary from the stack of words
 */
void narrowDownDictionary(stack<string>& words, set<string>& dictionary) {
    while(!words.empty()){
        dictionary.insert(words.top());
        words.pop();
    }
}
开发者ID:HannesTuhkala,项目名称:Cplusplus-Labs,代码行数:9,代码来源:evilhangman.cpp

示例10: comm_handle_reachable

void comm_handle_reachable( const msg_t& incoming ) {
  // add node to reachability list
  comm_reachability_list.insert( incoming.send_id );
}
开发者ID:Siddharthsas07,项目名称:utd,代码行数:4,代码来源:communication_server.cpp

示例11: comm_start

// Communication server setup
int comm_start( const char* config_file_path ) {
  int error = 0;

  if ( config_file_path == NULL ) {
    cout << "comm_start Invalid config file path " << config_file_path << endl;
    error = -1;
    return error;
  }

  // Open configuration file, read only
  string line;
  ifstream config_file( config_file_path, ios::in );

  if ( config_file.is_open() ) {
    // Read comms port
    std::getline( config_file, line );
    comm_port = str_to_uint( line );

    // Read coordinator ID
    std::getline( config_file, line );
    NODE_NETWORK_MASTER = str_to_uint( line );

    // Contact to add after each read from file
    node_contact_t contact;

    // All new contacts have no open sockets, so -1
    contact.sockfd = -1;

    // No nodes in the network yet
    NODE_NETWORK_SIZE = 0;

    // Read <node ID, node address>
    while ( config_file.good() ) {
      // Read node ID
      std::getline( config_file, line );
      contact.id = str_to_uint( line );

      // Read node address
      std::getline( config_file, line );
      contact.address = line;

      // Use TCP to talk to master, use UDP elsewise
      contact.type = ( contact.id == NODE_NETWORK_MASTER ? SOCK_STREAM : SOCK_DGRAM );

      error = comm_add_contact( contact );
      if ( error != 0 ) {
        cout << "comm_start Couldn't add contact "
          << contact.id << "@" << contact.address << endl;
        return error;
      }

      NODE_NETWORK_SIZE++;
    }
    
    // print_contact_list( comm_contacts );

    // The subnet of udp servers is all of th eservers minus the one master
    NODE_SUBNET_SIZE = NODE_NETWORK_SIZE - 1;

    // Finished reading from file
    config_file.close();

    // Initialize this node's vn info
    comm_vns[NODE_INFO.id].vn = 0;
    comm_vns[NODE_INFO.id].ru = NODE_SUBNET_SIZE;
    strncpy( comm_vns[NODE_INFO.id].text, "", sizeof("") );

    comm_print_vns();
    
    // Initialize the distributed file
    comm_file.path = "replica_" + uint_to_str( NODE_INFO.id ) + ".txt";
    comm_file.delimiters = "|";

    comm_file.print();
    
    // Initialize the distinguished object
    comm_distinguished.m = 0;
    comm_distinguished.n = 0;

    // Initialize the reachability list to all UDP nodes
    for ( contact_list_t::iterator it = comm_contacts.begin();
          it != comm_contacts.end();
          it++ ) {
      if ( it->first != NODE_NETWORK_MASTER ) {
        comm_reachability_list.insert( it->first );
      }
    }
    
    comm_print_reachability_list();

    // all other attrs default to OK values

    // Spawn tcp listener thread
    error = pthread_create( &(comm_tcp_listen_thread.id),
                            NULL,
                            comm_tcp_listen_thread_fun,
                            NULL );
    if ( error != 0 ) {
      cout << "comm_start Couldn't create TCP listen thread" << endl;
//.........这里部分代码省略.........
开发者ID:Siddharthsas07,项目名称:utd,代码行数:101,代码来源:communication_server.cpp

示例12: defined

static string
GetRealVariableHelper(const string &var, set<string> expandedVars)
{
    // Check for recursion in expanded vars
    if (expandedVars.count(var))
    {
        EXCEPTION1(RecursiveExpressionException, var);
    }
    expandedVars.insert(var);

    // If this variable is not an expression, then it is real
    Expression *expr = ParsingExprList::GetExpression(var);
    if (!expr)
    {
        // Found the real variable
        return var;
    }

    // Otherwise, descend into it; get the expression tree
    ExprNode *tree = ParsingExprList::GetExpressionTree(expr);
    if (!tree)
    {
        // We won't normally get here because error
        // conditions will usually throw exceptions.
        // Otherwise, every expression should have
        // a tree.
        return "";
    }

    // Get the leaves for this expression
    const vector<string> &varLeaves = tree->GetVarLeaves();
    if (varLeaves.empty())
    {
        delete tree;
        return "";
    }

    // For each leaf, look for a real variable
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
    // Don't use const iterator on win32 MSVC 6.
    for (std::vector<std::string>::iterator it = varLeaves.begin();
         it != varLeaves.end(); ++it)
#else
    for (std::vector<std::string>::const_iterator it = varLeaves.begin();
         it != varLeaves.end(); ++it)
#endif
    {
        string realvar = GetRealVariableHelper(*it, expandedVars);

        // If we found a real variable, return it!
        if (!realvar.empty())
        {
            delete tree;
            return realvar;
        }
    }

    // Didn't find any real variables
    delete tree;
    return "";
}
开发者ID:HarinarayanKrishnan,项目名称:VisIt26RC_Trunk,代码行数:61,代码来源:ParsingExprList.C

示例13: getDependencies

 DocumentSource::GetDepsReturn DocumentSourceUnwind::getDependencies(set<string>& deps) const {
     deps.insert(_unwindPath->getPath(false));
     return SEE_NEXT;
 }
开发者ID:DjComandos,项目名称:mongo,代码行数:4,代码来源:document_source_unwind.cpp

示例14: init

 void init() {
   const char *inv = "\n\r \t";
   for (int i = 0; inv[i]; i++) {
     invisible.insert(inv[i]);
   }
 }
开发者ID:jluwn,项目名称:Oilpriceforecast,代码行数:6,代码来源:Oilpriceforecast.cpp

示例15: count

	int count(int b1, int q1, int n1, int b2, int q2, int n2)
	{
		int i;
		int ans;
		map<int, int>::iterator it;
		temp.clear();
	
		if (b1 == 0)
			n1 = 1;
		if (b2 == 0)
			n2 = 1;
		if (q1 == 1 && b1 > 0)
			n1 = 1;
		if (q2 == 1 && b2 > 0)
			n2 = 1;
		if (q1 == 0 && b1 > 0 && n1 > 2)
			n1 = 2;
		if (q2 == 0 && b2 > 0 && n2 > 2)
			n2 = 2;

		fb1 = div(b1);
		fq1 = div(q1);
		fb2 = div(b2);
		fq2 = div(q2);
		res.clear();
		
		temp = fb1;
		res.insert(temp);
		for(i = 1;i < n1;i++)
		{
			for(it = fq1.begin();it != fq1.end();it++)
				temp[it->first] += it->second;
			if (temp.find(0) != temp.end())
			{
				temp.clear();
				temp[0] = 1;
			}
			if (res.find(temp) == res.end())
				res.insert(temp);
		}

		ans = res.size();
	
		temp = fb2;
		if (res.find(temp) == res.end())
			ans++;
		for(i = 1;i < n2;i++)
		{
			for(it = fq2.begin();it != fq2.end();it++)
				temp[it->first] += it->second;
			if (temp.find(0) != temp.end())
			{
				temp.clear();
				temp[0] = 1;
			}
			if (res.find(temp) == res.end())
				ans++;
		}

		return ans;
	}
开发者ID:Harvey-Ai,项目名称:ACM-ICPC,代码行数:61,代码来源:GeometricProgressions.cpp


注:本文中的set::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。