当前位置:网站首页>[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
边栏推荐
- 1D / 1D dynamic programming learning summary
- Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
- 3、 6 [Verilog HDL] gate level modeling of basic knowledge
- C语言:表达式求值(整型提升、算术转换 ...)
- Redis expired key cleaning and deletion policy summary
- Compile and debug mysql8 with clion under MacOS x
- Nvidia最新三维重建技术Instant-ngp初探
- Mobius inversion
- STM32 and FreeRTOS stack parsing
- PHP笔记(一):开发环境配置
猜你喜欢
NLLLoss+log_ SoftMax=CE_ Loss
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
Kernel PWN learning (3) -- ret2user & kernel ROP & qwb2018 core
元宇宙时代的职业规划与执行
Using JS to realize a thousandth bit
Number of islands
MySQL of database -- basic common query commands
Go language learning notes - array | go language from scratch
[COCI] lattice (dichotomy + tree divide and conquer + string hash)
SAP pi / PO soap2proxy consumption external WS example
随机推荐
Summary of wrong questions 1
阿里云架构师解读四大主流游戏架构
nn. Explanation of module class
重载、重写、隐藏的对比
Unfortunately, I broke the leader's confidential documents and spit blood to share the code skills of backup files
DVWA range practice
3、 6 [Verilog HDL] gate level modeling of basic knowledge
Flutter 的加载动画这么玩更有趣
AQS & reentrantlock implementation principle
Three ways to create objects in JS
SAP debug debug for in, reduce and other complex statements
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——4视觉系统中的多故障
[educational codeforces round 80] problem solving Report
SAP pi / PO function operation status monitoring and inspection
Redis exception read error on connection solution
Kettle experiment
Easy to understand subset DP
Random neurons and random depth of dropout Technology
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core