山东省第八届acm省赛C题 fireworks
2017-07-23 21:14
375 查看
题目来戳呀
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?
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).
2 2
2 2 2
0 3
1 2
3
题意:
放烟花,在xi位置上有ci个烟花,1秒钟一个分成两个,前一个后一个,此位置上的就没了。
一共有n个位置,问t秒后,在w位置上有多少个烟花。
想法:
写几组数据,用图的形式展开来(不要紧巴巴的真的就在数轴写啊+_+鬼能看出来啊)
某个位置上的图写出来发现类似杨辉三角,但是中间是加了0的
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 1 0 2 0 1 0 0 0
0 0 1 0 3 0 3 0 1 0 0
0 1 0 4 0 6 0 4 0 1 0
当所在的位置的奇偶性和时间的奇偶性相同时,发现符合杨辉三角。
符合杨辉三角的部分,即求组合数,C(n,m)=n!/m!(n-m)!,再对1e9+7取模;
因为取模之前的结果太大了,所以我们通过乘法逆元的方法来求,即除以一个数等于乘以这个数的逆元再取模,这位的逆元写的贼好
乘法逆元这里选择用快速幂的方法来求。
不符合杨辉三角的就是0。
ps: 哇卡哇卡不出来了QAQ
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.Example Input
1 2 02 2
2 2 2
0 3
1 2
Example Output
23
题意:
放烟花,在xi位置上有ci个烟花,1秒钟一个分成两个,前一个后一个,此位置上的就没了。
一共有n个位置,问t秒后,在w位置上有多少个烟花。
想法:
写几组数据,用图的形式展开来(不要紧巴巴的真的就在数轴写啊+_+鬼能看出来啊)
某个位置上的图写出来发现类似杨辉三角,但是中间是加了0的
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0
0 0 0 1 0 2 0 1 0 0 0
0 0 1 0 3 0 3 0 1 0 0
0 1 0 4 0 6 0 4 0 1 0
当所在的位置的奇偶性和时间的奇偶性相同时,发现符合杨辉三角。
符合杨辉三角的部分,即求组合数,C(n,m)=n!/m!(n-m)!,再对1e9+7取模;
因为取模之前的结果太大了,所以我们通过乘法逆元的方法来求,即除以一个数等于乘以这个数的逆元再取模,这位的逆元写的贼好
乘法逆元这里选择用快速幂的方法来求。
不符合杨辉三角的就是0。
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> using namespace std; typedef long long ll; const int mod=1e9+7; ll arr[100010]; void init()//求阶乘 { arr[0]=arr[1]=1; for(int i=2;i<=1e5;++i) arr[i]=(arr[i-1]*i)%mod; } ll PowerMod(ll a, ll b)//快速幂 { ll ans=1; a=a%mod; while(b>0) { if(b&1) ans=(ans*a)%mod; b>>=1; a=(a*a)%mod; } return ans; } ll cn(ll n,ll m) { return ((arr *PowerMod(arr[n-m],mod-2))%mod*PowerMod(arr[m],mod-2))%mod; } int main() { init(); int n,t,w; while(cin>>n>>t>>w) { ll ans=0; while(n--) { ll ci,xi; cin>>xi>>ci; ll k=abs(w-xi);//求绝对值 if((k&1)==(t&1)&&k<=t)//奇偶性相同就符合杨辉三角并且在时间范围内 ans=(ans+(ci*cn(t,(k+t)/2))%mod)%mod; } cout<<ans<<endl; } return 0; }
ps: 哇卡哇卡不出来了QAQ
相关文章推荐
- 2017山东省第八届ACM省赛 fireworks(杨辉三角 + 逆元)
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- 2017 年山东省第八届ACM省赛总结
- 山东省第八届ACM省赛 K 题 CF 解答(未完,待续)
- 山东省第八届ACM省赛 G 题(sum of power)
- 山东省第八届acm省赛C题 巨坑
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- Fireworks(山东省第8届ACM省赛)逆元,组合数
- 山东省第八届acm省赛D题 HEX
- 山东省第八届acm省赛 company
- 山东省第八届acm省赛D题HEX(组合数学)
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- 山东省第八届acm省赛 HEX
- 山东省第八届ACM省赛 I 题(Parity check)
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- 山东省第八届acm省赛 Return of the Nim
- [置顶] 2017年山东省第八届acm省赛总结
- 山东省第八届acm省赛E题 三分+二分
- 山东省第八届acm省赛B题 打表找规律