玄关,90分
  • 板块P1871 对撞机
  • 楼主AC_player
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/9/21 22:06
  • 上次更新2023/11/2 18:48:48
查看原帖
玄关,90分
670468
AC_player楼主2023/9/21 22:06
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m;
bool open[N];
int s[N],top=1;
int gcd(int a,int b){
	if (b==0) return a;
	return gcd(b,a%b);
}
int main(){
	cin>>n>>m;
	for (int j=1;j<=m;j++){
		char op;
		int x;
		cin>>op>>x;
		if (op=='-'){
			if (open[x]){
				open[x]=false;
				for (int i=1;i<top;i++){
					if (s[i]==x){
						s[i]=-1;
						break;
					}
				}
				cout<<"Success"<<endl;
			}
			else cout<<"Already off"<<endl;
		}
		else{
			if (open[x]) cout<<"Already on"<<endl;
			else{
				bool qwe=true;
				int f=0;
				for (int i=1;i<top;i++){
					if (s[i]==-1) continue;
					if (gcd(s[i],x)!=1){
						f=s[i];
						qwe=false;
						break;
					}
				}
				if(qwe){
					open[x]=true;
					s[top]=x;
					top++;
					cout<<"Success"<<endl; 
				}
				else cout<<"Conflict with "<<f<<endl;
			}
		}
	}
	return 0;
}

求大佬帮忙。

2023/9/21 22:06
加载中...