CodeForces - 993C Careful Maneuvering(几何+暴力+状态压缩)

30 篇文章 1 订阅
27 篇文章 1 订阅

题目链接:点击查看

题目大意:在 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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Frozen_Guardian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值