Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 放份代码，cin cout选手记得关闭同步流

Posted by sigongzi at 2018-05-03 21:36:07 on Problem 2003
In Reply To:答案 Posted by:sigongzi at 2018-05-03 21:33:11
```不得不说，这题有毒

cin cout选手记得关闭同步流
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <ctime>
#include <map>
#define MAXN 200005
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ba 823
#define mo 974711
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
string str[5005];
int fa[5005];
map<string,int> mmm;
vector<int> son[5005];
int N = 1,rt;
void dfs(int dep,int x) {
if(!x) return;
for(int i = 1 ; i <= dep ; ++i) cout<<"+";
cout<<str[x]<<endl;
for(int i = 0 ; i < son[x].size() ; ++i) {
dfs(dep + 1,son[x][i]);
}
}
void change(int f,int x) {
int y = son[x].size() ? son[x].front() : 0;
if(y) change(x,y);
son[x] = son[f];
if(y == 0) son[x].erase(son[x].begin());
for(int i = 0 ; i < son[x].size() ; ++i) {
if(son[x][i] == x) son[x][i] = y;
else fa[son[x][i]] = x;
}

}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
ios::sync_with_stdio(false);
cin>>str[1];rt = 1;
mmm[str[1]] = 1;
string s,t;
while(cin >> s) {
if(s == "print") {
dfs(0,rt);
for(int i = 1 ; i <= 60 ; ++i) cout<<"-";
cout<<endl;
}
else if(s == "fire"){
cin>>t;
int x = mmm[t];
int y = son[x].size() > 0 ? son[x].front() : 0;
for(int i = 0 ; i  < son[fa[x]].size() ; ++i) {
if(son[fa[x]][i] == x) {
if(y == 0) son[fa[x]].erase(son[fa[x]].begin() + i);
else {son[fa[x]][i] = y;}
break;
}
}

if(!y) continue;
else {fa[y] = fa[x];change(x,y);}
if(x == rt) rt = y;
son[x].clear();
}
else {
cin >> t;cin >> t;
mmm[t] = ++N;
str[N] = t;
fa[N] = mmm[s];
son[mmm[s]].pb(N);
}
}
return 0;
}```

Followed by:

User ID:
Title:

Content: