zoukankan      html  css  js  c++  java
  • POJ 1208

    水模拟,顺便学习了下deque

    教训是,一个很简单的题都花了很久才A。非常需要耐心,磨性子,读题理解。编码过程也因为模拟过程的烦躁,导致代码一直疏漏很多关键细节。

    If you really want. 写代码,是一件很需要静下来和自己好好交流的事情

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    #include <deque>
    using namespace std;
    
    const int maxn= 30;
    
    string op, wy;
    deque<int> S[maxn];
    stack<int> md;
    int pos[maxn];
    
    void Clear(int x)
    {
    	int px= pos[x];
    	while (x!= S[px].back()){
    		S[S[px].back()].push_back(S[px].back());
    		pos[S[px].back()]= S[px].back();
    		S[px].pop_back();
    	}
    }
    int main(int argc, char const *argv[])
    {
    	int n, a, b;
    	scanf("%d", &n);
    	for (int i= 0; i< n; ++i){
    		pos[i]= i;
    		S[i].push_back(i);
    	}
    
    	while (cin>>op && 'q'!= op[0]){
    		cin>>a>>wy>>b;
    		int pa= pos[a], pb= pos[b];
    		if (pa== pb){
    			continue;
    		}
    		if ('m'== op[0]){
    			Clear(a);
    		}
    		if ('n'== wy[1]){
    			Clear(b);
    		}
    		while (1){
    			md.push(S[pa].back());
    			if (S[pa].back()== a){
    				S[pa].pop_back();
    				break;
    			}
    			S[pa].pop_back();
    		}
    		while (!md.empty()){
    			S[pb].push_back(md.top());
    			pos[md.top()]= pb;
    			md.pop();
    		}
    	}
    
    	for (int i= 0; i< n; ++i){
    		printf("%d:", i);
    		while (!S[i].empty()){
    			printf(" %d", S[i].front());
    			S[i].pop_front();
    		}
    		putchar('
    ');
    	}
    	return 0;
    }
    
  • 相关阅读:
    DEM地形渲染中光源的方向
    python GDAL安装运行后提示找不到proj.db
    AO——将函数栅格数据集保存到磁盘
    arcgis影像分幅图裁剪
    arcgis判断线是否穿过面
    WSL 使用vscode写python
    python-gdal支持filegdb读写
    Chapter5 生长因子、受体和癌症
    Chapter6 胞内信号网络
    【转】B树、B+树、B*树
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14722267.html
Copyright © 2011-2022 走看看