E-一种因子游戏_牛客小白月赛80 (nowcoder.com)
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define per(i,a,b) for(int i=a;i<=b;i++)
#define ber(i,a,b) for(int i=a;i>=b;i--)
const int N = 300005;
int n, a[N], b[N];
vector<int> p[N];
int vis[N], match[N];
int gcd(int x, int y) {
return x ? gcd(y % x, x) : y;
}
int check(int u)
{
per(i, 0, p[u].size() - 1)
{
int v = p[u][i];
if (!vis[v])
{
vis[v] = 1;
if (!match[v] || check(match[v]))//v点可以匹配,或者v点可以被以前的点让出来
{
match[v] = u;
return 1;
}
}
}
return 0;
}
int main()
{
cin >> n;
per(i, 1, n) cin >> a[i];
per(i, 1, n) cin >> b[i];
per(i, 1, n)
per(j, 1, n)
if (gcd(b[i], a[j]) == 1)
p[i].push_back(j);
int ans = 0;
for (int i = 1; i <= n; i++)
{
memset(vis, 0, sizeof vis);
if (check(i)) ans++;
}
if (ans == n) printf("Bob\n");
else
printf("Alice\n");
return 0;
}