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


C++ priority_queue::empty方法代码示例

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


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

示例1: main

int main() {
		int tc, i, j,x;
		cin >> n >> m;
		
		vector <int> row;

		for (i = 0; i < n; i++) {
			row.clear();
			for (j = 0; j < m; j++) {
				cin >> x;
				row.push_back(x);
			}
			board.push_back(row);
		}



		cin >> tc;

		int stx, sty, enx, eny;
		while (tc--) {
			double sol = 0;
			double sol5 = 0;
			double sol2 = 0;
			double sol3 = 0;
			double sol4 = 0;
			int sol1;
			mp.clear();
			mp1.clear();
			cin >> stx >> sty;
			
			while (!pq.empty())
				pq.pop();
			enx = 0;
			eny = 0;
			sol = getdis(stx, sty, enx, eny);
			
		//	cout << sol << endl;
			mp.clear();
			mp1.clear();

			while (!pq.empty())
				pq.pop();
			enx = 0;
			eny = m - 1;
			sol2 = getdis(stx, sty, enx, eny);
		//	cout << sol << endl;
			mp.clear();
			mp1.clear();

			while (!pq.empty())
				pq.pop();
			enx = n - 1;
			eny = m - 1;
			sol3 = getdis(stx, sty, enx, eny);
		//	cout << sol << endl;
			mp.clear();
			mp1.clear();

			while (!pq.empty())
				pq.pop();
			enx = n - 1;
			eny = 0;
			sol4 = getdis(stx, sty, enx, eny);
			//cout << sol << endl;
			mp.clear();
			mp1.clear();

			sol5 = min(min(sol, sol2), min(sol3, sol4));
			cout << (int)(sol5 + 0.5) << "\n";
		}
		return 0;
}
开发者ID:shadowwalkers,项目名称:Artificial_Intelligence_codes,代码行数:73,代码来源:q35.cpp

示例2: CLR

template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
开发者ID:AmrARaouf,项目名称:algorithm-detection,代码行数:1,代码来源:8740444.cpp

示例3: work

void work()
{
    NODE tmpNode;
    while(!q.empty())
    {
        tmpNode = q.top();
        q.pop();
        //cout<<tmpNode.step<<" "<<tmpNode.val<<endl;
        if(tmpNode.val==0)
        {
            cout<<tmpNode.step<<endl;
            return;
        }
        else
        {
            int tmpx=tmpNode.x;
            int tmpy=tmpNode.y;
            if(tmpx>0)
            {
                node = tmpNode;
                int pos1=tmpx*3+tmpy;
                int pos2=(tmpx-1)*3+tmpy;
                swap(node.str[pos1],node.str[pos2]);
                node.x=tmpx-1;
                node.y=tmpy;
                node.step++;
                node.val = Astar(node);
                if(check(node.str))
                {
                    q.push(node);
                    s.insert(node.str);
                }
            }
            if(tmpx<2)
            {
                node = tmpNode;
                int pos1=tmpx*3+tmpy;
                int pos2=(tmpx+1)*3+tmpy;
                swap(node.str[pos1],node.str[pos2]);
                node.x=tmpx+1;
                node.y=tmpy;
                node.step++;
                node.val = Astar(node);
                if(check(node.str))
                {
                    q.push(node);
                    s.insert(node.str);
                }
            }
            if(tmpy>0)
            {
                node = tmpNode;
                int pos1=tmpx*3+tmpy;
                int pos2=tmpx*3+tmpy-1;
                swap(node.str[pos1],node.str[pos2]);
                node.x=tmpx;
                node.y=tmpy-1;
                node.step++;
                node.val = Astar(node);
                if(check(node.str))
                {
                    q.push(node);
                    s.insert(node.str);
                }
            }
            if(tmpy<2)
            {
                node = tmpNode;
                int pos1=tmpx*3+tmpy;
                int pos2=tmpx*3+tmpy+1;
                swap(node.str[pos1],node.str[pos2]);
                node.x=tmpx;
                node.y=tmpy+1;
                node.step++;
                node.val = Astar(node);
                if(check(node.str))
                {
                    q.push(node);
                    s.insert(node.str);
                }
            }
        }
    }
    cout<<"-1"<<endl;
}
开发者ID:jay2013,项目名称:NOI_ACM,代码行数:85,代码来源:Run_525135_Score_100_Date_2014-03-26.cpp

示例4: CLR

template<class T0, class T1, class T2> inline void CLR(priority_queue<T0, T1, T2> &Q){while (!Q.empty()) Q.pop();}
开发者ID:chyyuu,项目名称:ACM,代码行数:1,代码来源:HDU+4280.+Island+Transport[平面对偶].cpp

示例5: main

int main() {
	int parent[50];
	string line;
	string FILENAME = "input.txt";
	ifstream istream;

    int i, w, sz;
	char dir, starting = ' ';
    istream.open(FILENAME.c_str());
	if(istream.fail())
	{
		printf("Bad File name. Check readme for example.\n");
	}
	else{
		getline(istream,line);
		istringstream iss(line);
		iss>>dir;

		while(getline(istream,line)){
				
               istringstream iss(line);
               while(iss>>u>>v>>w){
					if(starting == ' '){
						starting = u;
						n.push_back(u);}

						if(std::find(n.begin(), n.end(), v) != n.end()) {
							/* n contains v */
							
						} else {
							/* n does not contain v */
							n.push_back(v);
						}

				  		G[u].push_back(pci(v, w));
						edges++;
					
					if(dir != 'D'){
						G[v].push_back(pci(u, w)); // for undirected
						edges++;
						}
			   }
        }
		nodes = n.size();
		
		
		
		// initialize graph
    for(i=1; i<=nodes; i++) D[n[i-1]] = INF;
   D[starting] = 0;
   Q.push(pci(starting, 0));


    // dijkstra
    while(!Q.empty()) {
       
		u = Q.top().first;
		
        Q.pop();
       
		if(F[u]){ 
			continue;
		}
        
		sz = G[u].size();
	
		for(i=0; i<sz; i++) {
            v = G[u][i].first;
            w = G[u][i].second;
			
 
			if(!F[v] && D[u]+w < D[v]) {
				
				
				D[v] = D[u] + w;
				
                Q.push(pci(v, D[v]));
				
				parent[v]  = u;
				
								
            }
        }
			
			F[u] = 1; 
    }
	
    // result
	printf("Dijkstra\nSource : %c\n", (char)n[0]);
    for(i=1; i<=nodes; i++){ 
		printf("Node %c : %d\n", (char)n[i-1], D[n[i-1]]);
	}
	printf("End Dijkstra\n");

	
	print(parent);
    }
	

	
//.........这里部分代码省略.........
开发者ID:neafie,项目名称:Shortestpaths,代码行数:101,代码来源:dijkstras.cpp

示例6: to_order_deliver

// Total-order deliver for order packets.
// msg -> pointer to msg object
void to_order_deliver(TO_Order * msg) {
	if( ntohl( msg->totalSeqNum ) > receiveSeqNum ) {
		orderBuffer.push( *msg );
	} else if( ntohl( msg->totalSeqNum ) == receiveSeqNum ) {

		unsigned int source_pid = ntohl( msg->pid );

		if( toMsgBuffers[ source_pid ].empty() ) {
			orderBuffer.push( *msg );
			return;
		}

		bool found = false;
		unsigned int seqNum = ntohl( msg->seqNum );
		forward_list<TO_Msg>::iterator iter;
		for( iter = toMsgBuffers[ source_pid ].begin(); iter != toMsgBuffers[ source_pid ].end(); iter++ ) {
			if( ntohl(iter->seqNum) == seqNum ) {

				receiveSeqNum++;

				pthread_mutex_lock( &console_lock );

				// Get current system time
				time_t tt = time(NULL);
				struct tm * tm_struct = localtime(&tt);
				char time_str[9];
				sprintf(time_str, "%d:%d:%d", tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec);

				// Deliver the message to the application
				char buffer[PAYLOAD+1];
				memcpy( buffer, iter->buf, ntohl(iter->length) );
				buffer[ ntohl(iter->length) ] = '\0';
				printf("Delivered \"%s\" from process %d, system time is %s\n", buffer, source_pid, time_str);

				// Check if there are any other messages to be delivered
				while( !orderBuffer.empty() ) {

					if( ntohl( orderBuffer.top().totalSeqNum ) != receiveSeqNum ) break;

					bool found2 = false;
					unsigned int source_pid2 = ntohl( orderBuffer.top().pid );
					unsigned int seqNum2 = ntohl( orderBuffer.top().seqNum );
					forward_list<TO_Msg>::iterator iter2;
					for( iter2 = toMsgBuffers[ source_pid2 ].begin(); iter2 != toMsgBuffers[ source_pid2 ].end(); iter2++ ) {
						if( ntohl(iter2->seqNum) == seqNum2 ) {
							memcpy( buffer, iter2->buf, ntohl(iter2->length) );
							buffer[ ntohl(iter2->length) ] = '\0';
							printf("Delivered \"%s\" from process %d, system time is %s\n", buffer, source_pid2, time_str);

							orderBuffer.pop();
							receiveSeqNum++;
							found2 = true;
							break;
						}
					}

					if( !found2 ) break;

				}

				pthread_mutex_unlock( &console_lock );

				found = true;
				break;

			}
		}
		if( !found ) {
			orderBuffer.push( *msg );
		}

	}
	// Do nth if we have already seen the order packet before
}
开发者ID:hungle2,项目名称:ece428,代码行数:76,代码来源:mp1.cpp

示例7: main

int main () {
    while (scanf("%d %d", &v, &e) && v && e) {
        scanf("%d %d", &c, &f);

        for (int i = 0; i < v; i++) {
            verts[i].n = i;
            verts[i].s = -1;
            for (int j = 0; j < v; j++) adj[i][j].clear();
        }

        for (int i = 0; i < e; i++) {
            scanf("%d %d %d", &a, &b, &w);
            adj[a][b].push_back(w);
        }

        verts[c].s = 0;
        fila.push(verts[c]);

        while (!fila.empty()) {
            act = fila.top();
            fila.pop();
            for (int i = 0; i < v; i++) {
                for (int j = 0; j < adj[act.n][i].size(); j++) {
                    if (verts[i].s == -1 || adj[act.n][i][j] + act.s < verts[i].s) {
                        verts[i].s = adj[act.n][i][j] + act.s;
                        fila.push(verts[i]);
                    }
                }
            }
        }
        
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                for (int k = 0; k < adj[i][j].size(); k++) {
                }
            }
        }

        bfs(f);

        for (int i = 0; i < v; i++) verts[i].s = -1;
        verts[c].s = 0;
        fila.push(verts[c]);

        while (!fila.empty()) {
            act = fila.top();
            fila.pop();
            if (act.n == f) break;
            
            for (int i = 0; i < v; i++) {
                for (int j = 0; j < adj[act.n][i].size(); j++) {
                    if (adj[act.n][i][j] == -1) continue;
                    if (verts[i].s == -1 || adj[act.n][i][j] + act.s < verts[i].s) {
                        verts[i].s = adj[act.n][i][j] + act.s;
                        fila.push(verts[i]);
                    }
                }
            }
        }
        
        while (!fila.empty()) {
            fila.pop();
        }

        printf("%d\n", verts[f].s);
    }
}
开发者ID:victorsenam,项目名称:treinos-old,代码行数:67,代码来源:samer08a.cpp

示例8: mergeFiles

void mergeFiles()
{
    int sizeOutBuffer = 0.2 * RAM;
    
    int numOB = sizeOutBuffer/recordSize;
    
    
    double x = ((double)((RAM-sizeOutBuffer)/NumBlocks));
    int numFilePtr = x/recordSize;
  
    // Store all file pointers in an array
    ifstream *file ;
    string str;
    for(int i=0; i<recordSize; i++) 
    {
        str = to_string(i+1);
        file = new ifstream(("split/file" + str).c_str());
        filePointers.push_back(file);
    }

    ifstream *fptr;
    string line;
    vector<string> record;
    int counter = 0;
    int countOutBuff = 0;
    
    for(int i=0; i<NumBlocks; i++)
    {
        fptr = filePointers[i];
        counter = 0;      
        
        while(getline(*fptr, line)) 
        {
            
            record = split(line, ',');
            maxheap.push(make_pair(record, i));
            ++counter;
            if (counter  == numFilePtr)
                break;
            
        }
    }
    

    
    ofstream outFile;
    outFile.open(HashMapArgs["output_file"]);
    string tempR;
    pair<vector<string>, int> mypair;
    vector<vector<string> > Records;

   
    while(!maxheap.empty()) 
    {
        mypair = maxheap.top();
        maxheap.pop();
        Records.push_back(mypair.first);
        
        // add new record from filepointer to heap
        if (getline(*filePointers[mypair.second], line))
        {
            record = split(line, ',');
            maxheap.push(make_pair(record, mypair.second));
        } 

        countOutBuff=1+countOutBuff;

        if (countOutBuff == numOB) 
        {
            
            for(int i=0; i<Records.size(); i++)
            {
                // only put specific columns into the file
                str = Records[i][ColsIndex[0]];

                for(int j=1; j<ColsIndex.size(); j++)
                    str += "," + Records[i][ColsIndex[j]];
                
                str = str + "\n";
                outFile << str;
            }

            
        }   
    }

    
    if (countOutBuff < numOB)
    {
        
        for(int i=0; i<Records.size(); i++)
        {
            str = Records[i][ColsIndex[0]];
            
            for(int j=1; j<ColsIndex.size(); j++) 
                str += "," + Records[i][ColsIndex[j]];
            
            str += "\n";
            outFile << str;
        }
//.........这里部分代码省略.........
开发者ID:varun1803,项目名称:contributions,代码行数:101,代码来源:merge.cpp

示例9: main

int main()
{
	picdir = "D:\\CNN\\0728\\CNN1\\0728\\res96\\";
	for (int i = st; i <= en; i++)
	{
		cout << i << "\n";
		char fitname[111];
		sprintf(fitname, "%s%d%s", "D:\\CNN\\c++gaussianfit\\fit", i, ".txt");
		FILE *foutfit = fopen(fitname, "w");
		choose = (int *)malloc(sizeof(int)*(JOINT + 1));
		tchoose = (int *)malloc(sizeof(int)*(JOINT + 1));
		for (int joint = 0; joint <= 13; joint++)
		{
			char heatmapname[MaxLen];
			sprintf(heatmapname,"%s%d_%d%s", "D:\\CNN\\CNN1\\results\\r_", i, joint, ".png");
			Mat img = imread(heatmapname);					
			int pmin = 11111, pmax = 0;
			//Find Maximum & Minimum
			fprintf(foutfit, "%d : \n", joint);
			for (int k = 0; k < Height; k++)
			{
				for (int l = 0; l < Width; l++)
				{					
					pmax = max(pmax, (int)img.at<cv::Vec3b>(k, l)[0]);
					pmin = min(pmin, (int)img.at<cv::Vec3b>(k, l)[0]);
				}
			}						
			int id=0;
			for (int k = 1; k <= Height; k++)
			{
				for (int l = 1; l <= Width; l++)
				{
					z[k][l] =(double) (img.at<cv::Vec3b>(k-1, l-1)[0] - pmin) / (double)(pmax - pmin);										
					savez[k][l] = z[k][l];
					pixel[id].data = z[k][l]; pixel[id].x = l; pixel[id++].y = k;
				}											
			}			
			//Sort by pixel intensity
			sort(pixel, pixel + Height*Width, cmp);
			int maxrow[NUM + 1], maxcol[NUM + 1];
			memset(used, 0, sizeof(used));
			for (int j = 1; j <= NUM; j++) maxrow[j] = maxcol[j] = -1;
			int num = 1;
			//Top Num Peak
			for (int j = 0; j < Height*Width && num<=NUM;j++)
			{
				if (used[pixel[j].y][pixel[j].x]) continue;
				maxrow[num] = pixel[j].y; maxcol[num] = pixel[j].x;				
				value[joint + 1][num] = pixel[j].data;
				for (int irow = max(1, maxrow[num] - 1); irow <= min(3 - (maxrow[num] - max(1, maxrow[num] - 1) + 1) + maxrow[num], 22); irow++)
				{
					for (int icol = max(1, maxcol[num] - 1); icol <= min(3 - (maxcol[num] - max(1, maxcol[num] - 1) + 1) + maxcol[num], 22); icol++)
					{
						used[irow][icol] = 1;
					}
				}
				num++;
			}
			int T = 2;
			for (num = 1; num <= NUM; num++)
			{
				//fprintf(foutfit, "        %d.   \n", num);
				if (maxrow[num] == -1) continue;
				int row1 = max(1, maxrow[num] - T), row2 = min(2 * T + 1 - (maxrow[num] - max(1, maxrow[num] - T) + 1) + maxrow[num], 22);
				int col1 = max(1, maxcol[num] - T), col2 = min(2 * T + 1 - (maxcol[num] - max(1, maxcol[num] - T) + 1) + maxcol[num], 22);
				double fmax = 0.0;
				pixeltype tmp[26];
				int id = 26;
				tmp[0].data = 0.0;
				q1.empty();
				q2.empty();
				for (int irow = 1; irow <= Height; irow++)
				{
					for (int icol = 1; icol <= Width; icol++)
					{
						if (irow >= row1 && irow <= row2 && icol >= col1 && icol <= col2)
						{
							z[irow][icol] = savez[irow][icol];
							q1.push(QMAX(icol, irow, z[irow][icol]));							
							q2.push(QMIN(icol, irow, z[irow][icol]));
							
						}
						else z[irow][icol] = 0.0;
						
					}
				}								
				if (joint == 2 && num == 7)
				{
					//cout << "----";
				}
				double maxrsquare = -11111.0;
				double maxx0, maxy0;
				xx0 = maxcol[num]; yy0 = maxrow[num];
				a1 = 1.0; sigma = 1.0; lastrsquare = 0.0;
				for (int iter = 1; iter <= 30; iter++)
				{
					init(z);
					getcenterpoint();
					computefitness();
					if (rsquare - lastrsquare < 1e-3) break;
//.........这里部分代码省略.........
开发者ID:caomw,项目名称:CNNHandPoseEstimationTotal,代码行数:101,代码来源:gaussianfit.cpp

示例10: if

int PalindromizationDiv1::getMinimumCost(string s, vector <string> op) {
    int n = op.size();
    for (int i = 0;i < n;i++)
    {
        if (op[i][0] == 'a')
        {
            sscanf(op[i].c_str(),"%s%s%d",tmp,o[i].c1,&o[i].cost);
            o[i].typ = 0;
        }
        else if (op[i][0] == 'e')
        {
            sscanf(op[i].c_str(),"%s%s%d",tmp,o[i].c1,&o[i].cost);
            o[i].typ = 1;
        }
        else if (op[i][0] == 'c')
        {
            sscanf(op[i].c_str(),"%s%s%s%d",tmp,o[i].c1,o[i].c2,&o[i].cost);
            o[i].typ = 2;
        }
    }
    node now;
    hash.clear();
    while (!Q.empty())  Q.pop();
    Q.push(node(s,0));
    hash.insert(s);
    int tim = 0;
    while (!Q.empty())
    {
        now = Q.top();
        Q.pop();
        if (palindrome(now.now) == true)    return now.cost;
        tmp1 = now.now;
        if (tmp1.size() > s.size()*2)   continue;
        for (int i = 0;i < n;i++)
        {
            if (o[i].typ == 0)
            {
                for (int j = 0;j <= tmp1.size();j++)
                {
                    tmp2 = tmp1.substr(0,j)+o[i].c1[0]+tmp1.substr(j,tmp1.size()-j);
                    if (hash.find(tmp2) == hash.end())
                    {
                        hash.insert(tmp2);
                        Q.push(node(tmp2,now.cost+o[i].cost));
                    }
                }
            }
            else if (o[i].typ == 1)
            {
                for (int j = 0;j < tmp1.size();j++)
                    if (tmp1[j] == o[i].c1[0])
                    {
                        tmp2 = tmp1.substr(0,j)+tmp1.substr(j+1,tmp1.size()-j-1);
                        if (hash.find(tmp2) == hash.end())
                        {
                            hash.insert(tmp2);
                            Q.push(node(tmp2,now.cost+o[i].cost));
                        }
                    }
            }
            else if (o[i].typ == 2)
            {
                for (int j = 0;j < tmp1.size();j++)
                    if (tmp1[j] == o[i].c1[0])
                    {
                        tmp2 = tmp1;
                        tmp2[j] = o[i].c2[0];
                        if (hash.find(tmp2) == hash.end())
                        {
                            hash.insert(tmp2);
                            Q.push(node(tmp2,now.cost+o[i].cost));
                        }
                    }
            }
        }
    }
    return -1;
}
开发者ID:mzry1992,项目名称:workspace,代码行数:78,代码来源:SRM_509_DIV_500.CPP

示例11: getdis

double getdis(int stx, int sty, int enx, int eny) {
    pid ex;
    pq.push(make_pair(0, make_pair(stx, sty)));

    int i;
    int j;

    if (board[stx][sty] == 1) {
        return 0;
    }

    int test;

    while (!pq.empty()) {
        ex = pq.top();
        pq.pop();
        mp1.insert(make_pair(ex.second, 1));
        mp.erase(ex.second);
        i = ex.second.first;
        j = ex.second.second;

        if ((ex.second.first == enx) && (ex.second.second == eny)) {
            return ex.first;
        }

        if ((j + 1 < m) && (board[i][j + 1] == 0) && (mp1.count(make_pair(i, j+1)) == 0)) {
            if (mp.count(make_pair(i, j + 1)) == 0) {
                pq.push(make_pair(ex.first + 1, make_pair(i, j+1)));
                mp.insert(make_pair(make_pair(i,j + 1),ex.first + 1));
            }
            else {
                test = mp[make_pair(i, j + 1)];
                if (test > ex.first + 1) {
                    pq.push(make_pair(ex.first + 1, make_pair(i, j+1)));
                    mp[make_pair(i,j+1)] = ex.first + 1;
                }
            }
        }

        if (((j + 1 < m) && (i + 1 < n)) && (board[i + 1][j + 1] == 0) && (mp1.count(make_pair(i + 1, j+1)) == 0)) {
            if (mp.count(make_pair(i + 1, j + 1)) == 0) {
                pq.push(make_pair(ex.first + rt2, make_pair(i + 1, j+1)));
                mp.insert(make_pair(make_pair(i + 1,j + 1),ex.first + rt2));
            }
            else {
                test = mp[make_pair(i + 1, j + 1)];
                if (test > ex.first + rt2) {
                    pq.push(make_pair(ex.first + rt2, make_pair(i+1, j+1)));
                    mp[make_pair(i+1,j+1)] = ex.first + rt2;
                }
            }
        }

        if ((i + 1 < n) && (board[i+1][j] == 0) && (mp1.count(make_pair(i + 1, j)) == 0)) {
            if (mp.count(make_pair(i + 1, j)) == 0) {
                pq.push(make_pair(ex.first + 1, make_pair(i + 1, j)));
                mp.insert(make_pair(make_pair(i + 1,j),ex.first + 1));
            }
            else {
                test = mp[make_pair(i + 1, j)];
                if (test > ex.first + 1) {
                    pq.push(make_pair(ex.first + 1, make_pair(i + 1, j)));
                    mp[make_pair(i+1,j)] = ex.first + 1;
                }
            }
        }

        if (((j - 1 >= 0) && (i + 1 < n)) && (board[i + 1][j - 1] == 0) && (mp1.count(make_pair(i + 1, j-1)) == 0)) {
            if (mp.count(make_pair(i + 1, j - 1)) == 0) {
                pq.push(make_pair(ex.first + rt2, make_pair(i + 1, j-1)));
                mp.insert(make_pair(make_pair(i + 1,j - 1),ex.first + rt2));
            }
            else {
                test = mp[make_pair(i + 1, j - 1)];
                if (test > ex.first + rt2) {
                    pq.push(make_pair(ex.first + rt2, make_pair(i+1, j-1)));
                    mp[make_pair(i+1,j-1)] = ex.first + rt2;
                }
            }
        }

        if ((j - 1 >= 0) && (board[i][j - 1] == 0) && (mp1.count(make_pair(i, j-1)) == 0)) {
            if (mp.count(make_pair(i, j - 1)) == 0) {
                pq.push(make_pair(ex.first + 1, make_pair(i, j - 1)));
                mp.insert(make_pair(make_pair(i,j - 1),ex.first + 1));
            }
            else {
                test = mp[make_pair(i, j - 1)];
                if (test > ex.first + 1) {
                    pq.push(make_pair(ex.first + 1, make_pair(i, j - 1)));
                    mp[make_pair(i,j-1)] = ex.first + 1;
                }
            }
        }

        if (((j - 1 >= 0) && (i - 1 >= 0)) && (board[i - 1][j - 1] == 0) && (mp1.count(make_pair(i-1, j-1)) == 0)) {
            if (mp.count(make_pair(i - 1, j - 1)) == 0) {
                pq.push(make_pair(ex.first + rt2, make_pair(i - 1, j-1)));
                mp.insert(make_pair(make_pair(i - 1,j - 1),ex.first + rt2));
            }
//.........这里部分代码省略.........
开发者ID:shadowwalkers,项目名称:Artificial_Intelligence_codes,代码行数:101,代码来源:q36.cpp

示例12: main

int main() {
	int query_n;
	bool is_queue, is_stack, is_pqueue;

	while (cin >> query_n) {
		is_queue = is_stack = is_pqueue = true;

		while (! S.empty()) S.pop();
		while (! Q.empty()) Q.pop();
		while (!PQ.empty()) PQ.pop();

		bool impossible = false;

		while (query_n--) {
			int q, x;
			cin >> q >> x;

			switch (q) {
				case 1:
					if (is_stack) S.push(x);
					if (is_queue) Q.push(x);
					if (is_pqueue) PQ.push(x);
					break;

				case 2:
					if (is_stack) {
						if (S.empty()) {
							impossible = true;
							break;
						}
						if (S.top() == x)
							S.pop();
						else
							is_stack = false;
					}

					if (is_queue) {
						if (Q.empty()) {
							impossible = true;
							break;
						}
						if (Q.front() == x)
							Q.pop();
						else
							is_queue = false;
					}

					if (is_pqueue) {
						if (PQ.empty()) {
							impossible = true;
							break;
						}
						if (PQ.top() == x)
							PQ.pop();
						else
							is_pqueue = false;
					}
					break;
			}
		}

		if (impossible) {
			cout << "impossible";
		} else
		if (is_queue + is_stack + is_pqueue >= 2) {
			cout << "not sure";
		} else {
			if (is_queue) {
				cout << "queue";
			} else
			if (is_stack) {
				cout << "stack";
			} else
			if (is_pqueue) {
				cout << "priority queue";
			} else {
				cout << "impossible";
			}
		}
		cout << endl;
	}

	return 0;
}
开发者ID:oybek,项目名称:sport-programming,代码行数:84,代码来源:11995.cpp

示例13: sol

void sol(int st, int ed, int n) {
    int v, m = 0, i;
    queue<int> Q;
    Q.push(ed);
    for(i = 1; i <= n; i++)
        used[i] = 0, cdis[i] = dis[i];
    while(!Q.empty()) {
        v = Q.front();
        Q.pop();
        for(it i = g[v].begin();
            i != g[v].end(); i++) {
            if(dis[i->to] == dis[v] - i->w) {
                SEG[m].s = dis[i->to];
                SEG[m].e = dis[v];
                SEG[m].v = v;
                SEG[m++].p = i;
                if(used[i->to] == 0) {
                    used[i->to] = 1;
                    Q.push(i->to);
                }
            }
        }
    }
    sort(SEG, SEG+m, cmps);
    LL ans = 0, odis = dis[ed], tmp;
    it ip;
    int runtime = 0, tj = 0;
    for(i = 0; i < m; i++) {
        while(!pQ2.empty() && SEG[i].s >= pQ2.top().e)
            pQ2.pop();
        tmp = SEG[i].s;
        while(i < m && SEG[i].s == tmp)
            pQ2.push(SEG[i]), i++;
        i--;
        if(pQ2.size() == 1) {
            SEG[tj++] = SEG[i];
            //printf("%lld %lld\n", SEG[i].s, SEG[i].e);
        }
    }
    while(!pQ2.empty()) pQ2.pop();
    sort(SEG, SEG+tj, cmpw);
    for(i = 0; i < tj; i++) {
        //printf("%lld %lld\n", SEG[i].s, SEG[i].e);
        if(SEG[i].p->w <= ans)
            continue;
        //if(runtime > 3000000)   break;
        for(ip = g[SEG[i].p->to].begin();
            ip != g[SEG[i].p->to].end(); ip++) {
            if(ip->to == SEG[i].v)
                break;
        }
        runtime += n;
        for(int j = 1; j <= n; j++) {
            if(cdis[j] <= SEG[i].s)
                pQ.push(ele(j, cdis[j]));
            else
                dis[j] = cdis[j]+ip->w;
            used[j] = 0;
        }
        SEG[i].p->w *= 2;
        ip->w *= 2;
        tmp = dijkstra(st, ed, n);
        if(tmp - odis >= ans)
            ans = tmp - odis;
        if(ans == ip->w/2)
            break;
        ip->w /= 2;
        SEG[i].p->w /= 2;
        i += rand()%2;
    }
    printf("%lld\n", ans);
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:72,代码来源:a458.cpp

示例14: main

int main(){

//    freopen("~/in","r",stdin);

    scanf("%d %d",&n,&m);
    scanf("%d %d",&x,&y);


    for (int i=0;i<m;i++){
        scanf("%d %d %d",&etmp.st,&etmp.ed,&etmp.length);
        edges[etmp.st].push_back(etmp);
        swap(etmp.st,etmp.ed);
        edges[etmp.st].push_back(etmp);
    }
    for (int i=1;i<=n;i++){
        scanf("%d %d",&dl[i],&ct[i]);
    }



    while(!pq.empty()){
        pq.pop();
    }
    memset(visted,0,sizeof(int)*(n+1));
    memset(shortest,0,sizeof(int)*(n+1));
    memset(sed,0,sizeof(sed));
    shortest[x] = -1;
    ntmp.value = 0;
    ntmp.id = x;
    pq.push(ntmp);
    bool flag = false;
    while(!pq.empty()){
        ntmp = pq.top();
        pq.pop();
        if (ntmp.id==y){
            printf("%I64d\n",ntmp.value);
            flag = true;
            break;
        }
        if (sed[ntmp.id] == true)  continue;
        sed[ntmp.id] = true;

        //扩展路径

        memset(visted,0,sizeof(int)*(n+1));
        roads.clear();
        visted[ntmp.id] = 2000000000;
        spread(ntmp.id,ntmp.id,dl[ntmp.id]);
        itro = roads.begin();
        for (;itro!=roads.end();itro++){
            new_node.id = itro->dest;
            if (new_node.id==ntmp.id) continue;
            new_node.value = itro->cost+ntmp.value;
            if (shortest[new_node.id]==0||new_node.value<shortest[new_node.id]){
                shortest[new_node.id] = new_node.value;
                pq.push(new_node);
            }
        }

    }
    if (flag==false)
        printf("-1\n");
    return 0;
}
开发者ID:AmrARaouf,项目名称:algorithm-detection,代码行数:64,代码来源:4302232.cpp

示例15: if

// A thread that takes packets out from the queue and send them based on their specified delay.
void *p_unicast_send_delay(void * arg) {

	// To allow the thread to be canceled by the main thread
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL);

	pthread_mutex_lock( &queue_lock );
	while( true ) {
		if( pktQueue.empty() ) {
			pthread_cond_wait( &queue_cv, &queue_lock ); // wait for the main thread to put a msg into the queue
		}

		bool goToIsEmpty = false;
		while( !goToIsEmpty ) {
			// Calculate delay = scheduled time that the packet should be sent - current time
			long int msgTime = pktQueue.top().timeWhenAdded;
			int msgDelay = pktQueue.top().delay;

		    struct timeval now;
			gettimeofday(&now,NULL);
			long int nowTime = now.tv_sec * 1000 + now.tv_usec / 1000;

			long int delay = msgTime + msgDelay - nowTime;

			if( delay <= 0 ) {

				// May happen in 2 cases:
				// - a newly added msg has delay = 0
				// - there are 2 consecutive msgs
				// Assumption: negligible in unit of second

				// Send the packet
				Q_Packet msgPacket = pktQueue.top();
				pktQueue.pop();
				unicast_send( msgPacket.dest_pid, msgPacket.pkt, msgPacket.length );
				// Go to check if the queue is empty
				goToIsEmpty = true;
				continue;

			} else {

				// Schedule time out
				struct timespec after;
			    long int ns = (now.tv_usec+1000UL*delay)*1000UL;
			    after.tv_sec = now.tv_sec + ns/1000000000UL;
			    after.tv_nsec = ns%1000000000UL;

				int rt = pthread_cond_timedwait( &queue_cv, &queue_lock, &after );

				if( rt == ETIMEDOUT ) {

					// Send the packet
					Q_Packet msgPacket = pktQueue.top();
					pktQueue.pop();
					unicast_send( msgPacket.dest_pid, msgPacket.pkt, msgPacket.length );
					// Go to check if the queue is empty
					goToIsEmpty = true;
					continue;

				} else if( rt == 0 ) {
					// Go to check if the newly-added packet has a negative delay
					continue;
				} else {
					printf("p_unicast_send_delay: pthread_cond_timedwait error: returned %d\n", rt);
					exit(1);
				}
			}
		}
	}
}
开发者ID:hungle2,项目名称:ece428,代码行数:70,代码来源:mp1.cpp


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