题目
思路
穷举法发现,有两种情况会导致“不公平”
①一个数字a有一次“in”(其他数字变成该数字a)并且有一次“out"(数字a变成其他数字)
②数字a有两次out(数字a有可能变两次其他不同的的数字)
(数据中可能会出现a两次变成同一个数字,这个时候对于游戏来说是公平的)
所以我们思路如下:
开一个set<pair<int,int>>来进行去重
开一个数组来记录若干个数字的out和in次数,
最后遍历一遍in和out的数字,
若out >= 2 || ( in >= 1 && out >= 1)就是不公平
没出现以上情况就是公平的
代码
#include<iostream>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int arr[10000][2];
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
memset(arr,0,sizeof(arr));
set<pair<int,int>> s;
int l;
int max = 0;
cin >> l;
for(int j = 0; j < l; j++)
{
int n,m;
cin >> n >> m;
if(n > max)
max = n;
if(m > max)
max = m;
if(m == n)
continue;
pair<int,int> p = {n,m};
s.insert(p);
}
for(auto x : s)
{
arr[x.first][0]++;
arr[x.second][1]++;
}
int Q = 1;
for(int j = 0; j <= max; j++)
{
if((arr[j][0] >= 1 && arr[j][1] >= 1) || arr[j][0] >= 2)
Q = 0;
}
if(Q)
cout << "Lucky dxw!" << endl;
else
cout << "Poor dxw!"<<endl;
}
return 0;
}