BestCoder Round #21 1002 Formula
来源:互联网 发布:ubuntu压缩为zip 编辑:程序博客网 时间:2024/06/15 20:38
Formula
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 996 Accepted Submission(s): 118
Problem Descriptionf(n)=(∏i=1nin−i+1)%1000000007 You are expected to write a program to calculate f(n) when a certain n is given.
InputMulti test cases (about 100000), every case contains an integer n in a single line. Please process to the end of file.[Technical Specification]1≤n≤10000000
OutputFor each n,output f(n) in a single line.
Sample Input2100
Sample Output2148277692题解 也说了如果直接打表会MLE 需要数据的你离散化处理,以前我知道一种和数据本身大小无关,只和数据相对大小有关的离散化,比如400,880,25,69我们可以等价的用3 4 1 2 表示他们的相对大小关系,但是本体需要用到每个数据,不能这样做,所以 我们可以按照一定的规则,比如这里我每个10个数据记录一个元素,这样每次输入 我就用我记录过的这个数来计算行的数比如我们记下n=10时的阶乘a[10],还有F(n)即s[10],那我们计算n=13的时候就可以用10这个记录 a[10]*11*12*13算出13的阶乘了,同理F(13)也是
#include <iostream>#include <algorithm>#include <string>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include<queue>#include<stack>#include<map>#include<set>using namespace std;#define lson ((root<<1)+1)#define rson ((root<<1)+2)#define MID ((l+r)>>1)typedef long long ll;typedef pair<int,int> P;#define For(i,t,n) for(int i=(t);i<(n);i++)const int maxn=1000001;const int base=1000;const int inf=999999;int mod=1000000007;int a[maxn];//计算阶乘int s[maxn];//计算答案int main(){ int n,m,i,j,k,t; ll ans=1,rec=1;j=0; for(i=1;i/10<maxn;i++) { rec=rec*i%mod; ans=ans*rec%mod; if(i/10>=j)//每隔10个数记录一次 { a[j]=rec; s[j++]=ans; } } while(~scanf("%d",&n)) { rec=a[n/10];//找到记录的元素 ans=s[n/10]; for(i=n/10*10+1;i<=n;i++)//用记录过的数来计算这个新的数 { rec=rec*i%mod; ans=ans*rec%mod; } printf("%lld\n",ans); } return 0;}
f(n)=(∏i=1nin−i+1)%1000000007 You are expected to write a program to calculate f(n) when a certain n is given.
Multi test cases (about 100000), every case contains an integer n in a single line. Please process to the end of file.[Technical Specification]1≤n≤10000000
For each n,output f(n) in a single line.
2100
2148277692题解 也说了如果直接打表会MLE 需要数据的你离散化处理,以前我知道一种和数据本身大小无关,只和数据相对大小有关的离散化,比如400,880,25,69我们可以等价的用3 4 1 2 表示他们的相对大小关系,但是本体需要用到每个数据,不能这样做,所以 我们可以按照一定的规则,比如这里我每个10个数据记录一个元素,这样每次输入 我就用我记录过的这个数来计算行的数比如我们记下n=10时的阶乘a[10],还有F(n)即s[10],那我们计算n=13的时候就可以用10这个记录 a[10]*11*12*13算出13的阶乘了,同理F(13)也是
0 0
- BestCoder Round #21 1002 Formula
- [BestCoder] Round #21 1002 - Formula | HDU 5139
- HDU5139 Formula && BestCoder Round #21 1002
- hdu 5139 Formula(BestCoder Round #21)
- BestCoder Round #21 02 Formula题解(规律+离散化)
- BestCoder Round #21 1002
- BestCoder Round #15 1002
- BestCoder Round #20 1002
- BestCoder Round #80 1002
- BestCoder Round #86 1002
- BestCoder Round #21 A
- ACM-BestCoder Round #21
- BestCoder Round #3 1002 BestCoder Sequence
- Bestcoder #21&&hdoj 5139 Formula 【另类打表之分块】
- Bestcoder Round #48 1001、1002
- BestCoder Round #75 1002模拟
- BestCoder Round #84 1002 Bellovin
- BestCoder Round #85 1001 1002
- JSP中System.out.println()与out.println()区别
- 编程中外部JS的良好写法
- cocos2dx 3d开源项目 fantasyWarrior3D 从零走起 5 [角色基类actor & AI实现]
- 【Linux】asm文件夹在那里
- MyEclipse:Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project。
- BestCoder Round #21 1002 Formula
- 进程通信学习笔记(记录上锁)
- 配置nfs服务器
- 经典笔试题目分析
- Java 多线程学习
- frame框架中验证码图片抓取(VB2010)
- Bitmap用法总结
- TD-LTE DwPTS占用OFDM符号数问题
- asp.net各种数据控件汇总