zoukankan      html  css  js  c++  java
  • hdu 5139 数据的离线处理

    所谓的数据离线处理,就是将所有的输入数据全部读入后,在进行统一的操作,这样当然有好处,比如让你算好多数的阶层,但是输入的每个数是没有顺序的,其实跟可以线性的解决,但是由于没有顺序的输入,这样处理的话复杂度就很高,若将输入的这些数据全部先存起来,再排序,然后按从小到大的顺序处理。

    f(n)=(i=1nini+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]
    1n10000000
    OutputFor each n,output f(n) in a single line.Sample Input
    2
    100
    Sample Output
    2
    148277692

    代码示例:
    struct node
    {
        ll f;
        ll ans;
        int id;
    }pre[eps];
    
    bool cmp1(node a, node b){
        return a.f < b.f;
    }
    
    bool cmp2(node a, node b){
        return a.id < b.id;
    }
    
    int main() {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        ll n;
        int k = 1;
        
        while(~scanf("%lld", &n)){
            pre[k].f = n;
            pre[k].id = k;
            k++;        
        }
        sort(pre+1, pre+k, cmp1);
        ll s = 1;
        ll aa = 1;
        int t = 1;
        for(ll i = 1; i <= 10000000; i++){
            s *= i;
            s %= mod;
            aa *= s;
            aa %= mod;
            while (pre[t].f == i){
                pre[t++].ans = (aa%mod);
            }
        }
        sort(pre+1, pre+k, cmp2);
        for(int i = 1; i < k; i++){
            printf("%lld
    ", pre[i].ans);
        }
        return 0;
    }
    
    东北日出西边雨 道是无情却有情
  • 相关阅读:
    观望Java-03:面向对象
    观望Java-02:基础语法
    观望Java-01:Java简介
    组件化开发——组件生命周期
    pug模板引擎——jade
    解决eclipse调试程序时source not found的问题
    Android中设置中文粗体的方法
    svn中编辑log message
    TortoiseSVN使用
    用TorToiseGit来管理github上的项目
  • 原文地址:https://www.cnblogs.com/ccut-ry/p/7894479.html
Copyright © 2011-2022 走看看