Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

放份代码,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
不得不说,这题有毒
先是让我OLE了无数次,我把putchar换成cout了,然后WA,只好对拍,拍出一组
错误原因是删除了某个点后size会减1,导致我遍历不到后面的了
例如YAA VED,我会删掉YAA,然后size = 1,i也指向1,循环结束了,我没更改VED的父亲
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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator