Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table

Posted ydddd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table相关的知识,希望对你有一定的参考价值。

链接:

https://codeforces.com/contest/1220/problem/B

题意:

Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that Mij=ai?aj where a1,…,an is some sequence of positive integers.

Of course, the girl decided to take it to school with her. But while she was having lunch, hooligan Grisha erased numbers on the main diagonal and threw away the array a1,…,an. Help Sasha restore the array!

思路:

a1 = sqrt(a1a2a1a3/(a2a3))
然后挨个计算.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int MAXN = 1e3+10;
LL MT[MAXN][MAXN];
LL a[MAXN];
int n;

int main()

    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++)
    
        for (int j = 1;j <= n;j++)
            cin >> MT[i][j];
    
    a[1] = sqrt((MT[1][2]*MT[1][3])/MT[2][3]);
    for (int i = 2;i <= n;i++)
        a[i] = MT[i-1][i]/a[i-1];
    for (int i = 1;i <= n;i++)
        cout << a[i] << ' ' ;
    cout << endl;

    return 0;

以上是关于Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table的主要内容,如果未能解决你的问题,请参考以下文章

B. Multiplication Table ( Codeforces Round #586 (Div. 1 + Div. 2) )

Codeforces Round #586 (Div. 1 + Div. 2) E. Tourism

Codeforces Round #586 (Div. 1 + Div. 2) C. Substring Game in the Lesson

C. Substring Game in the Lesson ( Codeforces Round #586 (Div. 1 + Div. 2) )

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)