山东省第八届ACM大学生程序设计 fireworks

fireworks

Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description

Hmz likes to play fireworks, especially when they are put regularly.
Now he puts some fireworks in a line. This time he put a trigger on each firework. With that trigger, each firework will explode and split into two parts per second, which means if a firework is currently in position x, then in next second one part will be in position x−1 and one in x+1. They can continue spliting without limits, as Hmz likes.
Now there are n fireworks on the number axis. Hmz wants to know after T seconds, how many fireworks are there in position w?

Input

Input contains multiple test cases.
For each test case:

  • The first line contains 3 integers n,T,w(n,T,|w|≤10^5)
  • In next n lines, each line contains two integers xi and ci, indicating there are ci fireworks in position xi at the beginning(ci,|xi|≤10^5).
Output

For each test case, you should output the answer MOD 1000000007.

Sample Input
1 2 0
2 2
2 2 2
0 3
1 2
Sample Output
2

3

0000000000100000000 第0s

0000000001010000000 第1s

0000000010201000000

0000000103030100000

0000001040604010000

我们取出来

1

11

121

1331

14641

我们发现是一个杨辉三角(组合数)

如果第一个数不是1,而是其他数。那么对应的其余位置都乘那个数即可。

那么我们就很好处理了,对于t分钟,第i个位置。

我们利用对称性处理右边即可,这样更简单。weizhi=fabs(i-w)//w为我们放第一个数的位置。weizhi就是相对位置,也就是杨辉三角要求的点的实际位置

如果t和weizhi同奇偶,那么就是杨辉三角,否则就是0 C(t,(weizhi+t)/2)

逆原快速求组合数即可。

#include<bits/stdc++.h> using namespace std; const long long maxn=200000; const long long p=1000000007; long long n,t,w; long long jie[110000]; void init() {     jie[0]=jie[1]=1;     for(int i=2; i<=100000; i++)         jie[i]=(jie[i-1]*i)%p; } long long mult(long long a,long long n) {     long long ans=1;     while(n)     {         if(n&1)ans=(ans*a)%p;         a=(a*a)%p;         n>>=1;     }     return ans; } long long C(long long  n,long long m) {     return ((jie[n]*mult(jie[n-m],p-2))%p*mult(jie[m],p-2))%p; } int main() {     init();     while(cin>>n>>t>>w)     {         long long ans=0;         for(int i=0;i<n;i++)         {             long long a1,b1;             cin>>a1>>b1;             long long julu=fabs(a1-w);             if((julu&1)==(t&1)&&julu<=t)             {                 ans=(ans+(b1*C(t,(julu+t)/2))%p)%p;             }         }         cout<<ans<<endl;     } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值