H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

题目描述:链接点此

这套题的github地址(里面包含了数据,题解,现场排名):点此

题目描述

Given n positive integers , your task is to calculate the product of these integers, The answer is less than

输入描述:

The first line of input is an integer n, the i-th of the following n lines contains the integer

输出描述:

Output one line with the answer 

示例1

输入

5
11
12
13
14
15

输出

360360题目意思:就是给你n个整数,求相乘的大小。

这题python和java很好过,因为py和java有大数,c++就比较难受了
n=int(input())
ans=1
for i in range(n):
    b=int(input())
    ans=ans*b
print(ans)

c++的后来在补

fft代码:超时了,回头再优化
@@ -0,0 +1,109 @@
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
#define mod 1000000007
#define N 350000
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const double pi = 3.141592653;
char s1[N>>1],s2[N>>1];
double rea[N],ina[N],reb[N],inb[N],ret[N],intt[N];
int i,len1,len2,lent,lenres,len;
int res[N>>1];
void FFT(double *reA,double *inA,int n,int flag)
{
    if (n == 1) return;
    int k,u,i;
    double reWm = cos(2*pi/n) , inWm = sin(2*pi/n);//?????
    if (flag) inWm = -inWm;
    double reW = 1.0 , inW = 0.0;
    for (k = 1,u = 0;k < n; k += 2,u++)//??????????????
        {ret[u] = reA[k]; intt[u] = inA[k];}
    for (k = 2;k < n; k += 2)
        {reA[k/2] = reA[k]; inA[k/2] = inA[k];}
    for (k = u,i = 0;k < n && i < u; k++,i++)
        {reA[k] = ret[i]; inA[k] = intt[i];}
    FFT(reA,inA,n/2,flag); FFT(reA+n/2,inA+n/2,n/2,flag);
    fo(k,0,n/2-1)//???
        {
            int tag = n / 2 + k;
            double reT = reW * reA[tag] - inW * inA[tag];
            double inT = reW * inA[tag] + inW * reA[tag];
            double reU = reA[k] , inU = inA[k];
            reA[k] = reU + reT; inA[k] = inU + inT;
            reA[tag] = reU - reT; inA[tag] = inU - inT;
            double reWt = reW * reWm - inW * inWm;
            double inWt = reW * inWm + inW * reWm;
            reW = reWt; inW = inWt;
        }
}
void mul()
{
        memset(res, 0 , sizeof(res));
        memset(rea, 0 , sizeof(rea));
        memset(ina, 0 , sizeof(ina));
        //memset(reb, 0 , sizeof(reb));
       // memset(inb, 0 , sizeof(inb));
        len1 = strlen(s1); len2 = strlen(s2);
        lent = (len1 > len2 ? len1 : len2);
        len = 1;
        while (len < lent) len <<= 1;
        len <<= 1;
        fo(i,0,len-1)
        {
            if (i < len1) rea[i] = (double) s1[len1-i-1] - ‘0‘;
            if (i < len2) reb[i] = (double) s2[len2-i-1] - ‘0‘;
            ina[i] = inb[i] = 0.0;
        }
    FFT(rea,ina,len,0); FFT(reb,inb,len,0);//???a??b?????????
    fo(i,0,len-1)//???c?????????
        {
            //printf("%.5lf %.5lf\n",rea[i],ina[i]);
            double rec = rea[i] * reb[i] - ina[i] * inb[i];
            double inc = rea[i] * inb[i] + ina[i] * reb[i];
            rea[i] = rec; ina[i] = inc;
        }
    FFT(rea,ina,len,1);//???c??????????
    fo(i,0,len-1) {rea[i] /= len; ina[i] /= len;}

    fo(i,0,len-1) res[i] = (int)(rea[i] + 0.5);
    fo(i,0,len-1) res[i+1] += res[i] / 10 , res[i] %= 10;

    lenres = len1 + len2 + 2;
    while (res[lenres] == 0 && lenres > 0) lenres--;
    int kk=0;
    fd(i,lenres,0)
        s1[kk++]=res[i]+‘0‘;
}
int main()
{
       freopen("temin.txt","r",stdin);
    freopen("temout.txt","w",stdout);
    int n;
    scanf("%d",&n);
    if(n==1)
    {
        scanf("%s",s1);
        printf("%s\n",s1);
    }
    else
    {
        scanf("%s",s1);
        for(int i=1;i<n;i++)
        {
            scanf("%s",s2);
            mul();
        }
        printf("%s\n",s1);
    }
    return 0;
}



原文地址:https://www.cnblogs.com/fantastic123/p/8947493.html

时间: 2024-11-07 15:06:11

H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)的相关文章

A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155 Accepted Submission(s): 110   Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If

hdu 1757 A Simple Math Problem (乘法矩阵)

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2441    Accepted Submission(s): 1415 Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) =

hdu1757 A Simple Math Problem(矩阵快速幂)

题目: A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3522    Accepted Submission(s): 2130 Problem Description Lele now is thinking about a simple function f(x). If x < 10 f

矩阵十题【八】 HDU 1715 A Simple Math Problem

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: If x < 10   ,则  f(x) = x. If x >= 10 ,则  f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10); 给出k,m和a0~a9,求f(k)%m,  k<2*10^9 , m < 10^5 这是一个递推式,故可以用矩阵乘法来求 和上题类似,具体思路过程见上题

hdu1757-- A Simple Math Problem(矩阵快速幂优化)

A Simple Math Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2

HDU 1757 A Simple Math Problem

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 108 Accepted Submission(s): 77   Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If

hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2791    Accepted Submission(s): 1659 Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) =

hdu 5974 A Simple Math Problem

A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1645    Accepted Submission(s): 468 Problem Description Given two positive integers a and b,find suitable X and Y to meet th

hdoj 1757 A Simple Math Problem

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(