HDU5139 - Formula(找规律+离散化)
来源:互联网 发布:mysql数据库重启命令 编辑:程序博客网 时间:2024/05/17 19:18
【题目】
Formula
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 42 Accepted Submission(s): 24
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
Source
BestCoder Round #21
【分析】
暴力出前6个即可得出规律,设ans[n]-ans[n-1] = a,则ans[n] = n*a[n-1]*ans[n-1];这样就能出结果了,可是n最大有10^7,开数组超内存,而一共只有10^5组数据,所以根据所有数据的n值从小到大排序,再同一算出即可。
【AC CODE】670ms
#include <cstdio>#include <cstring>#include <cctype>#include <cmath>#include <map>//#include <unordered_map>#include <queue>#include <stack>#include <vector>#include <string>#include <algorithm>using namespace std;typedef long long LL;#define rep(i,a,n) for(int i = a; i < n; i++)#define repe(i,a,n) for(int i = a; i <= n; i++)#define per(i,n,a) for(int i = n; i >= a; i--)#define clc(a,b) memset(a,b,sizeof(a))const int INF = 0x3f3f3f3f, MAXN = 10000000+10, MOD = 1000000007, MAXT = 100000+10;struct NODE{int id,a;NODE(int c = 0, int b = 0){id = c, a = b;}bool operator<(NODE& t)const{return a < t.a;}}p[MAXT];map<int,LL> vis;int main(){#ifdef SHYfreopen("e:\\1.txt", "r", stdin);//freopen("e:\\out.txt", "w", stdout);#endifint t = 0;int n;while(~scanf("%d%*c", &n)){p[t] = NODE(t,n);t++;}sort(p,p+t);LL ans, lans = 1;LL a,la = 1;int cnt = 0;repe(i,1,p[t-1].a){ans = (i*(la)%MOD)*(LL)(lans)%MOD;lans = ans;a = i*la%MOD;la = a;while(p[cnt].a == i){vis[p[cnt++].id] = ans;}}rep(i,0,t)printf("%I64d\n", vis[i]);return 0;}
0 0
- HDU5139 - Formula(找规律+离散化)
- HDU5139 Formula (找规律+离线处理)
- BestCoder Round #21 02 Formula题解(规律+离散化)
- hdu5139 Formula(离线操作)
- HDU 2492 Ping pong (树状数组+离散化+找规律)
- Wandering Robots hdu6229 离散化+思维找规律+bitset标记
- HDU5139 Formula && BestCoder Round #21 1002
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 找规律
- 找规律!
- 找规律
- 找规律,
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- 找规律
- _InterlockedAnd _InterlockedOr等原子级安全运算
- JStorm - 安装配置
- TI提供的例子简介
- 【spoj7001】莫比乌斯反演
- 关于Mongodb的全面总结,学习mongodb的人,可以从这里开始!
- HDU5139 - Formula(找规律+离散化)
- C语言枚举类型
- Android中解析XML
- scrapy分布式的应用学习笔记(一)
- sendmail
- 指向函数的指针
- mini6410 用fb显示bitmap
- TCP的状态迁移图详解
- hdu2955 Robberies(背包问题)