zoukankan      html  css  js  c++  java
  • ACdream群(167655270)原创群赛(3) 1028 Problem G Multiplication

    1028: Multiplication
    Time Limit: 2 Sec  Memory Limit: 128 MB
    Submit: 547  Solved: 126
    [Submit][Status][Web Board]
    Description
    
    If C=A⋄B, then
    C[k]=∑max(i,j)=kA[i]⋅B[j]mod(109+7)
    .
    
    Work out sequence C=A⋄B for given sequence A and B.
    Input
    
    The first line contains a integer n, which denotes the length of sequence A,B.
    
    The second line contains n integers a1,a2,…,an, which denote sequence A.
    
    The thrid line contains n integers b1,b2,…,bn, which denote sequenceB.
    
    (1≤n≤105,0≤ai,bi≤109)
    Output
    
    n integers, which denotes sequence C.
    Sample Input
    2 1 2 3 4
    Sample Output
    3 18
    HINT
    
    Source
    
    ftiasch

    http://www.acdream.net/problem.php?id=1028

    O(n^2) 算法是肯定超时的
    想下就可以发现这样就是可以用O(N)的算法 记录前i个数和就可以了

    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define N 100002
    #define Max 1000000007
    #define __int64 long long
    __int64 a[N],b[N],aa[N],bb[N];
    int main()
    {
        int n;
        int i;
        while(scanf("%d",&n)!=EOF)
        {
            for(i=1;i<=n;i++)
             {
                 scanf("%lld",&a[i]);
                 aa[i]=aa[i-1]+a[i];
             }
            for(i=1;i<=n;i++)
             {
                 scanf("%lld",&b[i]);
                 bb[i]=bb[i-1]+b[i];
             }
           __int64 ans;
           printf("%lld",a[1]*b[1]%Max);
           for(i=2;i<=n;i++)
           {
               ans=(a[i]*(bb[i-1]%Max)+b[i]*(aa[i-1]%Max)+a[i]*b[i]%Max)%Max;
               printf(" %lld",ans);
           }
        printf("\n");
        }
        return 0;
    }
  • 相关阅读:
    启用数据库 aspnetstate 会话状态
    窗体设计器
    玩转hyper-v
    PDF,IMAGE,HTML,WORD,EXCEL 互操作
    在线浏览office 文件
    使用c#操作txt
    C#里调用 MysqlDB
    c#控件攻略宝典之ListBox控件
    c# word文档与二进制数据的相互转换
    C#对话框的使用
  • 原文地址:https://www.cnblogs.com/372465774y/p/2779485.html
Copyright © 2011-2022 走看看