zoukankan      html  css  js  c++  java
  • FZU1404 Andy的作业

    Andy的作业
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    Andy每天都有很多作业要做,他的老师总是在说“这些作业你明天必须交上来……”。现在他找你帮忙做其中的一项作业,给出N个整数A1, A2, ..., AN,有 M 个询问 q (L, R),对于每个询问,你要输出一个整数,第L个数到第R个数的乘积,这个乘积不会超过1000位。

    Input

    输入包含多组测试数据。每组数据第一行为两个整数N,M (N <= 800, M <= 1000) 接下来N行,给出这N个整数。然后M行,每行两个整数L R表示一个询问。

    Output

    对于每个询问,输出相应的结果。当所有询问结束之后输出“Homework Finished”。

    Sample Input

    10 5 9 7 9 6 4 9 5 8 3 4 5 9 3 8 8 10 10 10 1 7 1 1 1 1 1

    Sample Output

    4320 77760 96 4 612360 Homework Finished 1 Homework Finished

    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<climits>
    #include<queue>
    #include<vector>
    #include<map>
    #include<sstream>
    #include<set>
    #include<stack>
    using namespace std;
    typedef long long ll;
    //ifstream fin("input.txt");
    //ofstream fout("output.txt");
    //fin.close();
    //fout.close();

    ll a[850];
    ll b[850];
    ll c[1100];
    const ll maxn=1e8;
    int lef,rig,cnt,last,n,m;

    void mul(ll x)
    {
    int i,j;ll temp,rest;
    rest=0;

    for(i=1;i<=last;i++)
    {
    temp=x*c[i]+rest;
    c[i]=temp%10;
    rest=temp/10;


    }
    while(rest)
    {
    c[++last]=rest%10;
    rest/=10;
    }
    while(last>=1&& !c[last])
    {

    last--;

    }

    }

    int main()
    {
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
    for(i=1;i<=n;i++)
    scanf("%I64d",&a[i]);

    while(m--)
    {
    cnt=0;
    scanf("%d%d",&lef,&rig);
    i=lef;
    while(i<=rig)
    {
    ll s=1;
    while( s<=maxn&&i<=rig )
    {
    s*=a[i++];
    }
    b[cnt++]=s;
    }
    memset(c,0,sizeof(c));
    c[1]=1;
    last=1;
    for(i=0;i<cnt;i++)
    {

    mul(b[i]);


    }
    if(!last ) puts("0");
    else
    {
    for(i=last;i>=1;i--)
    {
    printf("%I64d",c[i]);
    }
    putchar(' ');
    }


    }
    puts("Homework Finished");

    }


    return 0;
    }

  • 相关阅读:
    新年献礼 技术胖262集前端免费视频 让您走的更容易些
    Eruda 一个被人遗忘的调试神器
    你(可能)不知道的web api
    含有阶乘的幂级数和
    sin x 特解的假设
    将y=arctanx展开为x的幂级数
    判断数项级数是否收敛
    ubuntu中用安装字体的方法解决文档中的音标乱码
    英语单词
    用递归实现汉诺塔
  • 原文地址:https://www.cnblogs.com/yskyskyer123/p/4531974.html
Copyright © 2011-2022 走看看