本文主要是介绍FOJ有奖月赛-2016年8月 Problem A Daxia Wzc's problem(找规律),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Accept: 42 Submit: 228
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题:
Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d;
首先让Daxia求出数列A(0)前n项和,得到新数列A(1);
然后让Daxia求出数列A(1)前n项和,得到新数列A(2);
接着让Daxia求出数列A(2)前n项和,得到新数列A(3);
…
最后让Daxia求出数列A(m-1)前n项和,得到新数列A(m);
Input
测试包含多组数据,每组一行,包含四个正整数a(0<=a<=100),d(0<d<=100),m(0<m<=1000),i(1<=i<=1000000000).
Output
每组数据输出一行整数,数列A(m)的第i项mod1000000007的值.
Sample Input
Sample Output
Hint
A(0): 1 2 3 4
A(1): 1 3 6 10
A(2): 1 4 10 20
A(3): 1 5 15 35
So the 4th of A(3) is 35.
Cached at 2016-08-17 20:49:17.
解题思路:
其实这个题目可以在纸上画一画,然后就能找到规律了。
然后就发现规律了。
My Code:
/**
2016 - 08 - 17 晚上
Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const LL MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{LL res=0,ch,flag=0;if((ch=getchar())=='-')flag=1;else if(ch>='0'&&ch<='9')res=ch-'0';while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';return flag?-res:res;
}
int Scan_Int()///输入外挂
{int res=0,ch,flag=0;if((ch=getchar())=='-')flag=1;else if(ch>='0'&&ch<='9')res=ch-'0';while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';return flag?-res:res;
}
void Out(LL a)///输出外挂
{if(a>9)Out(a/10);putchar(a%10+'0');
}
LL Inv[MAXN];
void Get_Inv()
{Inv[1] = 1;for(int i=2; i<MAXN; i++)Inv[i] = ( (MOD-MOD/i)*Inv[MOD%i] ) % MOD;
}
int main()
{Get_Inv();LL a, d, m, n;while(cin>>a>>d>>m>>n){LL ans = 1, tmp=n-1;for(int i=0; i<=m; i++){ans = (ans*tmp)%MOD;tmp++;}ans = (ans*d)%MOD;LL res = 1;tmp = n;for(int i=1; i<=m; i++){res = (res*tmp)%MOD;ans = (ans*Inv[i+1])%MOD;tmp++;}res = (res*a)%MOD;for(int i=1; i<m; i++)res = (res*Inv[i+1])%MOD;cout<<(res+ans)%MOD<<endl;}return 0;
}
这篇关于FOJ有奖月赛-2016年8月 Problem A Daxia Wzc's problem(找规律)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!