zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    UIScrollView(滚动视图)
    NSJSONSerialization(json序列化)
    手势(UIGestureRecognizer)
    mac常用命令
    ios设备相关
    UITextField
    cocos2d学习笔记
    NSTimer(定时器)
    git命令
    Java 线程的终止-interrupt
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11626598.html
Copyright © 2011-2022 走看看