码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-10-06 11:43:25      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:ide   思路   ade   positive   and   计算   school   decided   max   

链接:

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

标签:ide   思路   ade   positive   and   计算   school   decided   max   

原文地址:https://www.cnblogs.com/YDDDD/p/11626598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!