当前位置:网站首页>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();
}边栏推荐
- OSI、TCP/IP(A1)
- CANopen communication - PDO and SDO
- 暑假第三周
- Hcip third day notes
- Arm architecture and programming 3 -- key control LED (based on Baiwen arm architecture and programming tutorial video)
- IP地址、子网划分(A2)
- Problèmes de localisation et de planification des itinéraires (Lingo, mise en œuvre de MATLAB)
- 1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
- Hospital generic cabling
- How to finally generate a file from saveastextfile in spark
猜你喜欢

Database paradigm and schema decomposition

Problèmes de localisation et de planification des itinéraires (Lingo, mise en œuvre de MATLAB)

After the interview with 20 or 30 companies, there is no offer that you can't get after the Android interview

Hospital generic cabling

Hcip experiment

Jenkins multitâche construction simultanée

Hcip day 5 notes

Hcip day 6 notes

Ora-12899 error caused by nchar character

Matlab绘制双坐标图(全网最简单)
随机推荐
How to synchronize MySQL database when easycvr platform is upgraded to the latest version v2.5.0?
Is it safe for Huatai Securities to open an account? Is it true? Is it formal
Hcip day 8 notes
C byte array and class mutual conversion
Win11 highlights of win11 system
MGRE GRE OSPF process in hcip
Arm architecture and programming 1 -- LED flashing (based on Baiwen arm architecture and programming tutorial video)
NetCore-如何保证ICollection或List私有化不被外部修改?
Code reading methods and best practices
Arm architecture and programming 3 -- key control LED (based on Baiwen arm architecture and programming tutorial video)
Hcip day 12 notes
How to use the directory classification function of the new version of easycvr (v2.5.0)?
SCM learning notes 6 -- interrupt system (based on Baiwen STM32F103 series tutorials)
Measurement and acquisition of permanent magnet motor parameters (inductance, resistance, pole number, flux linkage constant)
php7 垃圾回收机制详解
Hundred million financing events account for more than 30%. Where is the next stop for super automation? -- Manfu Technology
Summary of volatile interview in concurrent programming
Network type (notes on the third day)
医院无线网络系统设计
The first day of little bear pie