2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)

Posted charliewade

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)相关的知识,希望对你有一定的参考价值。

Guanguan‘s Happy water

4000ms 

262144K

 

Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerator is full, but he still wants to store happy water every day. Here comes the solution: He first constructs a p-sequence: p_1p1?p_2p2?, ..., p_kpk?, where p_1+p_2+...+p_k=1p1?+p2?+...+pk?=1. Then he chooses an number ii among 11 to kk, where number ii has the probability p_ipi? to be chosen. After that, he drinks the happy water stored on the ii-th day before the current day and stores the same amount of happy water back into the refrigerator again. Let the amount of happy water stored on the ii-th day be f_ifi?. Given the amount of happy water stored in the first kk days and the expected amount of the next kk days(which means, from the k+1k+1-th day to the 2k2k-th day), could you help Guanguan figure out the sum of the expected amount of happy water stored during the first nn days) (Be aware that every element of ff has moded 1e9+71e9+7 when input datas, and your output should mod 1e9+71e9+7 as well)

Input

The first line is TT (1 \le T \le 201T20), indicating the number of input sets. For each set of inputs, the first line is kk and nn (1 \le k \le 701k70, 1 \le n \le 10^181n1018), and the second line is 2k2k numbers, respectively representing a_1a1?a_2a2?, ..., a_kak?f_k+1fk+1?f_k+2fk+2?, ..., f_2kf2k?.

Output

For each data, output a non-negative integer indicating (\sum_i=1^n f_i) \mod 10^9+7(i=1n?fi?)mod109+7.

样例输入

2
1 9
2 2
2 8
6 5 5 5

样例输出

18
41

 

思路:

suma=(a1+a2+。。。+ak)

sumf=(f1+f2+。。。+f3)

①n<=k,ans=a1+a2+。。。+an;

②n<=2k,ans=suma+f1+f2+。。。+f(n-k);

③n>2k,ans=suma+((n-k)/k)*sumf+(   f1+f2+。。。+f( (n-k)%k )  ).

注意取模就行

 

AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=1e6+7;
 5 ll mod=1e9+7;
 6 ll a[maxn],f[maxn];
 7 int main()
 8 
 9     int t;
10     scanf("%d",&t);
11     while(t--)
12         int k;
13         ll n,suma=0,sumf=0,k2;
14         scanf("%d",&k);
15         k2=ll(k);
16         scanf("%lld",&n);
17         for(int i=1;i<=k;++i)
18             scanf("%lld",&a[i]),suma=(suma+a[i])%mod;
19         for(int i=1;i<=k;++i)
20             scanf("%lld",&f[i]),sumf=(sumf+f[i])%mod;
21         ll ans=0;
22         if(k2>=n)
23             for(int i=1;i<=int(n);++i)
24                 ans=(ans+a[i])%mod;
25             printf("%lld\n",ans%mod);
26         
27         else
28             ans=suma%mod;
29             ll nu=((n-k2)/k2);
30             int len=n-nu*k2-k2;
31             nu%=mod;
32             ans=(nu*sumf+ans)%mod;
33             for(int i=1;i<=len;++i)
34                 ans=(ans+f[i])%mod;
35             printf("%lld\n",ans%mod);
36         
37     
38     return 0;
39 
40 /*
41 2
42 2 100000000000000000
43 6 5 5 5
44 */

 

以上是关于2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)的主要内容,如果未能解决你的问题,请参考以下文章

[ACM-ICPC 2018 沈阳网络赛] G. Spare Tire (思维+容斥)

[ACM-ICPC 2018 沈阳网络赛] Ka Chang (dfs序+树状数组+分块)

2017.11.11 ACM-ICPC2017亚洲区域赛(沈阳)重现赛 7/13 Rank10

ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229

ACM-ICPC 2017 沈阳赛区现场赛 G. Infinite Fraction Path && HDU 6223

2019.09.142019icpc沈阳网络赛