T3 萌新 40pt 求助
  • 板块P9518 queue
  • 楼主AC_CSP
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/12 19:03
  • 上次更新2023/11/3 04:13:58
查看原帖
T3 萌新 40pt 求助
481527
AC_CSP楼主2023/8/12 19:03

希望大佬们能给个 Hack\text{Hack} 或者帮看看/kk

#include<bits/stdc++.h>
#define DE cout<<"qwq\n"
using namespace std;
const int N=1e5+7;
map<string,int> mp;
string name[N];
queue<int>q,q2;//队列/游戏
int a[N],b[N];//队列中/玩游戏
int n;
int cnt;
bool out[N];//是否出队
int main(){
 ios::sync_with_stdio(false);
 cin.tie(0),cout.tie(0);
 cin>>n;
 for(int i=1;i<=n;i++){
  string str;
  cin>>str;
  if(str=="start"){
   while(!q2.empty()){
    int u=q2.front();q2.pop();
    a[u]=1,b[u]=0;q.push(u);
   }
   if(!q.size()) cout<<"Error\n";
   else{
	int u=q.front();q.pop();
	while(out[u]&&q.size()) u=q.front(),q.pop();
	if(out[u]!=1){
	 a[u]=1;
	 b[u]=1;
	 q2.push(u);
	 cout<<name[u];
	 if(!q.empty()){
	  u=q.front();
	  q.pop();
	  while(out[u]&&q.size()) u=q.front(),q.pop();
	  if(out[u]!=1){
	   a[u]=1,b[u]=1;
	   q2.push(u);
	   cout<<" "<<name[u];	
	  }
	 }
	 cout<<"\n";
	}
	else
	 cout<<"Error\n";
   }
  }
  if(str=="arrive"){
   cin>>str;
   int p=mp[str];
   if(p&&out[p]){
	q.push(p),out[p]=0;a[p]=1;
	cout<<"OK\n";
   }
   else if(!p){
	mp[str]=++cnt,name[cnt]=str;
	//cout<<cnt<<"::"<<"\n";
	q.push(cnt),out[cnt]=0;a[cnt]=1;
	cout<<"OK\n";
   }
   else cout<<"Error\n";
  }
  if(str=="leave"){
   cin>>str;
   int p=mp[str];
   //if(str=="D") cout<<"qwq"<<b[p]<<"\n"; 
   if(a[p]&&!b[p]&&!out[p]){
	a[p]=b[p]=0,out[p]=1;
	cout<<"OK\n";
   } 
   else cout<<"Error\n";
  }
 }
 return 0;
}
2023/8/12 19:03
加载中...