当前位置:网站首页>hdu-7141 Ball (bitset)
hdu-7141 Ball (bitset)
2022-07-24 01:45:00 【I want to eat egg yolk and meat dumplings】
Portal :Problem - 7141
The question : stay m*m There are... On my chessboard n A little bit , Ask how many options you have Choose three points each time and find the Manhattan distance between two Make the median Manhattan distance a prime number .
analysis : Obviously, the Manhattan distance between any two points can be preprocessed , Then, when enumerating the prime Manhattan distance, try how many third-party points satisfy the condition . Originally thought it was similar to matrix counting points , But the Manhattan distance around a point is irregular , Besides, there are two points , We need some special treatment . Consider sorting Manhattan distances and then using bitset,dp[i][k]=1 Indication point k To i The distance of is less than the current distance , Add... Every time (dp[a]^dp[b]).count() that will do .
Code :
#include<bits/stdc++.h>
using namespace std;
#define int long long
// #define int __int128
#define pii pair<int,int>
#define endl '\n'// Interactive questions need endl Refresh //
const int maxn=1e6+5;
const int N=1e7;
int flag[N+10];//flag[i]=0 i Prime number
int prime[N+10];
int cnt;
void init()
{
flag[0]=1,flag[1]=1;//0 and 1 Not prime
for(int i=2;i<=N;i++)
{
if(flag[i]==0) prime[++cnt]=i;
for(int j=1;j<=cnt&&prime[j]*i<=N;j++)
{
flag[i*prime[j]]=1;
if(i%prime[j]==0) break;// According to the unique decomposition theorem , Each number is only in prime[j] Is its minimum factor when marked (12=2*6!=4*3)
}
}
}
int x[2005],y[2005];
bitset<2005>dp[2005];
struct node
{
int a,b,dis;
}e[2005*2005];
int cal(int a,int b)
{
return abs(x[a]-x[b])+abs(y[a]-y[b]);
}
bool cmp(node c,node d)
{
return c.dis<d.dis;
}
void solve()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) dp[i].reset();
for(int i=1;i<=n;i++)
{
cin>>x[i]>>y[i];
}
int ct=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
e[++ct]={i,j,cal(i,j)};
}
}
sort(e+1,e+ct+1,cmp);
int ans=0;
for(int i=1;i<=ct;i++)
{
int a=e[i].a,b=e[i].b,dis=e[i].dis;
if(!flag[dis]) ans+=(dp[a]^dp[b]).count();
dp[a][b]=dp[b][a]=1;
}
cout<<ans<<endl;
}
signed main()
{
init();
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--) solve();
}边栏推荐
- [bdsec CTF 2022] partial WP
- Summary of HCIA knowledge points
- Vantui, axiso, FAQs and usage:
- NetCore-如何保证ICollection或List私有化不被外部修改?
- How the next dbcontext of efcore advanced SaaS system supports multi database migration
- Retinal network based on enhanced spatial attention (ESA UNET)
- Decrypt redis to help the e-commerce seckill system behind the double 11
- Arm architecture and programming 7 -- exceptions and interrupts (based on Baiwen arm architecture and programming tutorial video)
- C byte array and class mutual conversion
- Install SSL Certificate in Litespeed web server
猜你喜欢

Hcip day 10 notes

Notes - record the solution to the failure of @refreshscope dynamic refresh configuration

Structure the second operation of the actual combat battalion module

Exchange 2013 SSL certificate installation document

CANopen communication - PDO and SDO
![[hiflow] regularly send Tencent cloud SMS sending group](/img/af/40e4a16e4214ae2fc4781e85364a64.png)
[hiflow] regularly send Tencent cloud SMS sending group

Research on retinal vascular segmentation based on GAN using few samples

What is the Gantt chart function of Zen

数字签名技术简介

141. Circular linked list
随机推荐
Local empowerment learning
刚开始使用,请教些问题和教程或分享帖子
Hcip second day notes
Using tessellation in unity
Hcip day 4 notes
Retinal network based on enhanced spatial attention (ESA UNET)
Just started to use, ask some questions and tutorials or share posts
How to use the directory classification function of the new version of easycvr (v2.5.0)?
Research on retinal vascular segmentation based on GAN using few samples
SCM learning notes 8 -- keys and external interrupts (based on Baiwen STM32F103 series tutorials)
Hcip network type, PPP session, data link layer protocol
xxl-job使用注意事项
2022 global developer salary exposure: China ranks 19th, with an average annual salary of $23790
Arm architecture and programming 7 -- exceptions and interrupts (based on Baiwen arm architecture and programming tutorial video)
OSPF (fourth day notes)
Problèmes de localisation et de planification des itinéraires (Lingo, mise en œuvre de MATLAB)
Add of cmake_ dependencies
Vessel Segmentation in Retinal Image Based on Retina-GAN
Summary of volatile interview in concurrent programming
SCM learning notes 9 -- Serial Communication (based on Baiwen STM32F103 series tutorials)