Bestcoder #21&&hdoj 5139 Formula 【另类打表之分块】
来源:互联网 发布:hptv手机电视软件 编辑:程序博客网 时间:2024/06/06 00:17
Formula
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 155 Accepted Submission(s): 69
Problem Description
You are expected to write a program to calculate f(n) when a certain n is given.
Input
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
Please process to the end of file.
[Technical Specification]
Output
For each n,output f(n) in a single line.
Sample Input
2100
Sample Output
2148277692
题意:计算i从1~n的i^(n-i-1)的乘积。
普通打表 超内存+超时,,,
不妨将所有的输入数据都存进一个结构体中一个是no(表示输入时的顺序)一个是num(表示输入的数据n),再按照num的大小排序,之后依次找与num相等的数,并将其的值赋给out中
没想到还可以这样。。学习了
代码:
#include <cstdio>#include <cstring>#include <algorithm>#define LL __int64using namespace std;const LL M = 100005;const LL mod = 1000000007;struct node{LL no, num;}s[M];LL out[M];int cmp(node a, node b){return a.num < b.num;}int main(){LL n, cnt = 0;while(scanf("%I64d", &n) == 1){s[cnt].no = cnt;s[cnt].num = n;cnt++;}LL a, b, index = 0, i;sort(s, s+cnt, cmp);a = 1; b = 1;for(i = 1; index != cnt; i ++){a = (a*i)%mod;b = (b*a)%mod;while(index !=cnt &&s[index].num == i){out[s[index++].no] = b;}}for(i = 0; i < cnt; i ++){printf("%I64d\n", out[i]);}return 0;}
0 0
- Bestcoder #21&&hdoj 5139 Formula 【另类打表之分块】
- [BestCoder] Round #21 1002 - Formula | HDU 5139
- hdu 5139 Formula(BestCoder Round #21)
- BestCoder Round #21 1002 Formula
- HDOJ 5139 Formula 离线
- hdoj 5139Formula
- HDU5139 Formula && BestCoder Round #21 1002
- 分块打表
- NP(分块打表)
- BestCoder Round #21 02 Formula题解(规律+离散化)
- hdoj 1297 打表
- BZOJ 3758 数数 分块打表
- lightoj 1234 - Harmonic Number 【分块打表】
- bzoj 3758: 数数 分块打表
- 51nod1799 二分答案(分块打表)
- [分块打表] [Luogu P1822] 魔法指纹
- 2017百度之星资格赛:1005. 寻找母串(卡特兰数+分块打表)
- HDU 6084 | 2017百度之星资格赛 1005 卡特兰数 + 分块打表
- 扫描二维码自动识别手机APP下载地址
- VS2010下Bundler的使用以及cygwin的配置
- 构建C协程之setjmp/long_jmp篇
- 优秀链接收集
- View 的API讲解
- Bestcoder #21&&hdoj 5139 Formula 【另类打表之分块】
- 主成分分析 详解
- 构建C协程之ucontext篇
- ViewPager相互嵌套,里层ViewPager无法滑动
- 实例解析linux内核I2C体系结构
- 在windows下安装yii2框架
- Qt学习之路-简易画板4(鼠标点击拖动图形功能)
- RakNet(59)学习 -- PHP Directory Server(目录服务器)
- ZigZag Conversion