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;
}

转载于:https://www.cnblogs.com/372465774y/archive/2012/11/20/2779485.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的用C++面向对象编写的有限判定的程序: ```cpp #include <iostream> #include <vector> #include <set> using namespace std; class Group { private: int size; vector<vector<int>> multiplication_table; public: Group(int n) { size = n; multiplication_table.resize(n, vector<int>(n)); } void set_element(int i, int j, int value) { multiplication_table[i][j] = value; } bool is_associative() { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { for (int k = 0; k < size; k++) { if (multiplication_table[i][multiplication_table[j][k]] != multiplication_table[multiplication_table[i][j]][k]) { return false; } } } } return true; } bool has_identity() { for (int i = 0; i < size; i++) { bool is_identity = true; for (int j = 0; j < size; j++) { if (multiplication_table[i][j] != j || multiplication_table[j][i] != j) { is_identity = false; break; } } if (is_identity) { return true; } } return false; } bool has_inverses() { for (int i = 0; i < size; i++) { bool has_inverse = false; for (int j = 0; j < size; j++) { if (multiplication_table[i][j] == 0 && multiplication_table[j][i] == 0) { has_inverse = true; break; } } if (!has_inverse) { return false; } } return true; } bool is_closed() { set<int> group_elements; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { group_elements.insert(multiplication_table[i][j]); } } return group_elements.size() == size; } bool is_group() { return is_closed() && is_associative() && has_identity() && has_inverses(); } }; int main() { Group G(4); G.set_element(0, 0, 0); G.set_element(0, 1, 1); G.set_element(0, 2, 2); G.set_element(0, 3, 3); G.set_element(1, 0, 1); G.set_element(1, 1, 2); G.set_element(1, 2, 3); G.set_element(1, 3, 0); G.set_element(2, 0, 2); G.set_element(2, 1, 3); G.set_element(2, 2, 0); G.set_element(2, 3, 1); G.set_element(3, 0, 3); G.set_element(3, 1, 0); G.set_element(3, 2, 1); G.set_element(3, 3, 2); if (G.is_group()) { cout << "G is a group." << endl; } else { cout << "G is not a group." << endl; } return 0; } ``` 这个程序定义了一个`Group`类,其中包含一个矩阵表示法,以及判定一个有限是否成立的四个方法: - `is_associative()`:判断是否满足结合律; - `has_identity()`:判断是否存在单位元; - `has_inverses()`:判断是否每个元素都有逆元; - `is_closed()`:判断是否在乘法下封闭。 最后,在`main()`函数中,我们构造了一个4阶,并检查它是否是一个
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值