当前位置:网站首页>[CF 1425d] danger of mad snakes
[CF 1425d] danger of mad snakes
2022-04-23 09:43:00 【Zimba_】
The question :
There is one 1000 × 1000 1000\times 1000 1000×1000 Of the lattice . Yes n n n The snake is in the square , Each snake tells you the coordinates in the grid ( X i , Y i ) (X_{i},Y_{i}) (Xi,Yi) And a weight B i B_{i} Bi.
Then choose any of them m m m A snake , For each selected snake , It and all satisfaction m a x ( ∣ X ′ − X ∣ , ∣ Y ′ − Y ∣ ) < = R max(|X'-X|,|Y'-Y|)<=R max(∣X′−X∣,∣Y′−Y∣)<=R Located at ( X ′ , Y ′ ) (X',Y') (X′,Y′) All snakes will be killed .
For one of the options , Its weight is the square of the sum of the weights of all snakes killed in the selection .
Find the sum of the weights of all the selected methods .
Ideas :
Consider the square of the sum of weights ( B i + B j + B k ) 2 (B_{i}+B_{j}+B_{k})^{2} (Bi+Bj+Bk)2, Let's take the square form apart and turn it into B i 2 + B j 2 + B k 2 + 2 B i B j + 2 B i B k + 2 B j B k B_{i}^{2}+B_{j}^{2}+B_{k}^{2}+2B_{i}B_{j}+2B_{i}B_{k}+2B_{j}B_{k} Bi2+Bj2+Bk2+2BiBj+2BiBk+2BjBk.
Consider calculating a single square term B i 2 B_{i}^{2} Bi2 The contribution of , The total number of times each snake is selected × B i 2 \times B_{i}^{2} ×Bi2.
Let's calculate Total cases − - − The number of cases not selected That's it .
Consider calculating the multiplication of two terms 2 B i B j 2B_{i}B_{j} 2BiBj The contribution of , Is the number of times both snakes are selected × 2 B i B j \times 2B_{i}B_{j} ×2BiBj.
Let's excuse this , Calculation The number of cases where neither is selected + i i i Number of cases selected + j j j Number of cases selected - The total number of cases That's it .
Code :
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll fpow(ll a,ll n)
{
ll sum=1,base=a%mod;
while(n!=0)
{
if(n%2)sum=sum*base%mod;
base=base*base%mod;
n/=2;
}
return sum;
}
ll inv(ll a)
{
return fpow(a,mod-2);
}
ll jie[1000005],rjie[1000005];
void initJie(ll n)
{
jie[0]=1;
for(ll i=1;i<=n;i++)jie[i]=jie[i-1]*i%mod;
for(ll i=0;i<=n;i++)rjie[i]=inv(jie[i]);
}
ll C(ll n,ll k)
{
if(k>n)return 0;
else return jie[n]*rjie[k]%mod*rjie[n-k]%mod;
}
ll n,m,r;
ll x[2005],y[2005],b[2005];
bitset<2005>num[2005],tmp;
ll get1(ll i)
{
return (b[i]*b[i]%mod*(C(n,m)-C(n-num[i].count(),m))%mod+mod)%mod;
}
ll get2(ll i,ll j)
{
tmp=num[i]|num[j];
return 2*b[i]*b[j]%mod*(C(n-tmp.count(),m)+(C(n,m)-C(n-num[i].count(),m))-C(n-num[j].count(),m))%mod;
}
int main()
{
initJie(100000);
scanf("%lld%lld%lld",&n,&m,&r);
for(ll i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&x[i],&y[i],&b[i]);
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
if(max(abs(x[j]-x[i]),abs(y[j]-y[i]))<=r)
{
num[i].set(j);
}
}
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=(ans+get1(i))%mod;
}
for(ll i=1;i<=n;i++)
{
for(ll j=i+1;j<=n;j++)
{
ans=(ans+get2(i,j))%mod;
}
}
printf("%lld\n",(ans%mod+mod)%mod);
return 0;
}
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230621424809.html
边栏推荐
- The sap export excel file opens and shows that the file format and extension of "XXX" do not match. The file may be damaged or unsafe. Do not open it unless you trust its source. Do you still want to
- Creation of raid0 and RAID5 and Simulation of how RAID5 works
- JS DOM event
- 成功的DevOps Leader 应该清楚的3个挑战
- 从知识传播的维度对比分析元宇宙
- Solving Lucas number and combination theorem
- 亚马逊云科技入门资源中心,从0到1轻松上云
- MySQL of database -- Fundamentals
- SAP pi / PO function operation status monitoring and inspection
- Buuctf [actf2020 freshman competition] include1
猜你喜欢
SAP RFC_ CVI_ EI_ INBOUND_ Main BP master data creation example (Demo customer only)
JS node operation, why learn node operation
Random neurons and random depth of dropout Technology
Dropout技术之随机神经元与随机深度
Installation of data cleaning ETL tool kettle
论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——3背景
如何实现根据照片获取地理位置及如何防御照片泄漏地理位置
JS DOM event
Kettle experiment
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
随机推荐
P1446 [hnoi2008] cards (Burnside theorem + DP count)
面试官:说几个PHP常用函数,幸好我面试之前看到了这篇文章
Redis 内存占满导致的 Setnx 命令执行失败
Pre parsing of JS
Give the method of instantiating the object to the new object
[geek challenge 2019] havefun1
Set the maximum width of the body, but why does the background color of the body cover the whole page?
SAP ECC connecting SAP pi system configuration
SQL used query statements
Redis exception read error on connection solution
Alibaba cloud architects interpret the four mainstream game architectures
Go language learning notes - slice, map | go language from scratch
Go language learning notes - array | go language from scratch
亚马逊云科技入门资源中心,从0到1轻松上云
个人主页软件Fenrus
阿里云架构师解读四大主流游戏架构
Kettle experiment
Random neurons and random depth of dropout Technology
如何实现根据照片获取地理位置及如何防御照片泄漏地理位置
SAP salv14 background output salv data can directly save files and send emails (with sorting, hyperlink and filtering format)