AtCoder Problems 评级难度:。
题意
- 给你长度为 的序列 和 。
- 求有多少个非负整数 满足:有一种修改序列 的方法使得 。
- 按升序输出所有满足条件的 。
- 。
思路
不难证明,当 时, 成立。
所以说,问题可以从求 转化为求 (若 ,则 符合条件)。
枚举 ,让 ,再对两个序列进行比较,时间复杂度 。
注意答案可能有重复的,可以把答案扔到 set 里,既能去重还能自动排序。
#include <bits/stdc++.h>
#define each(x,y) for(auto &x:y)
using namespace std;
const int N = 2020;
int n, tmp;
vector<int> a, b, p;
set<int>ans;
bool judge(int x)
{
p=a;
each(i,p)
i^=x;
sort(p.begin(), p.end());
return b==p;
}
void solve()
{
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>tmp;
a.push_back(tmp);
}
for(int i=1; i<=n; i++)
{
cin>>tmp;
b.push_back(tmp);
}
sort(b.begin(), b.end());
each(i,b)
{
tmp=a[0]^i;
if(judge(tmp)) ans.insert(tmp);
}
cout<<ans.size()<<endl;
each(i,ans)
cout<<i<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}