题目链接:点击查看
题目大意:在 x = -100 的直线上有 n 个敌方飞船,在 x = 100 的直线上有 m 个敌方飞船,现在在 x = 0 的直线上可以选择两个点作为诱饵,使得两侧的飞船瞄准射击,问如何才能击落尽量多的飞船
题目分析:因为 n 和 m 只有 60,所以在 x == 0 时至多有 n * m 个交点,然后去 O( n^2 ) 去枚举交点暴力计算答案即可,对于每个交点来说,状压记录一下两侧可以击落的飞船,然后维护一下最大值就好了
更简单的一个思路就是,因为两侧的飞船分别位于 x = -100 和 x = 100 这两条直线上,换句话说,其交点在 x = 0 的位置等价于其中点的位置,所以直接维护所有中点的位置然后继续上述操作就可以了
一个自己踩到的坑就是,__builtin_popcount()函数的形式参数是 unsinged int,所以需要自己手写一个函数用来计算二进制下有多少个 “1”
还有一个坑就是两个诱饵所在的位置可能相同
代码:
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int N=1e6+100;
int a[N],b[N];
map<int,pair<LL,LL>>mp;
int cal(LL x)
{
int ans=0;
while(x)
{
if(x&1)
ans++;
x>>=1;
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",a+i);
for(int i=0;i<m;i++)
scanf("%d",b+i);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
mp[a[i]+b[j]].first|=(1LL<<i);
mp[a[i]+b[j]].second|=(1LL<<j);
}
int ans=0;
for(auto it1:mp)
for(auto it2:mp)
ans=max(ans,cal(it1.second.first|it2.second.first)+cal(it1.second.second|it2.second.second));
printf("%d\n",ans);
return 0;
}