标签:
A - 小女警的异世界之战-
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> #include<map> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXN (100+10) #define MAXL (1000+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} int n; int h2[MAXN]; class str { public: // int i; char s[MAXL]; void mem(){s[0]=0;} friend bool operator<(str a,str b){return strcmp(a.s,b.s)<0; } friend bool operator==(str a,str b){return strcmp(a.s,b.s)==0; } }s1[MAXN],s2[MAXN]; map<str,int> h; bool fl; void dfs(int l1,int r1,int l2,int r2) { if (l1<r1&&l2<r2) { int p=h2[l2]; int len1=p-l1; if (len1>0) dfs(l1,p-1,l2+1,l2+len1); if (r1-l1+1-len1-1>0) dfs(p+1,r1,l2+len1+1,r2); } if (fl) printf(" ");else fl=1; printf("%s",s2[l2].s); } int main() { // freopen("A.in","r",stdin); // freopen("A.out","w",stdout); while(scanf("%d",&n)==1) { h.clear(); if (n==0) return 0; For(i,n) s1[i].mem(),s2[i].mem(); For(i,n) scanf("%s",s1[i].s); For(i,n) { h[s1[i]]=i; } For(i,n){ scanf("%s",s2[i].s); h2[i]=h[s2[i]]; } fl=0; dfs(1,n,1,n); printf("\n"); } return 0; }
NOJ 2015年陕西省程序设计竞赛网络预赛(正式赛)(小女警的异世界之战-前序中序求后序)
标签:
原文地址:http://blog.csdn.net/nike0good/article/details/45771379