AtCoder题解 —— AtCoder Beginner Contest 184 —— A - Determinant

题目相关

题目链接

AtCoder Beginner Contest 184 A 题,https://atcoder.jp/contests/abc184/tasks/abc184_a

Problem Statement

Given is a 2×2 matrix A=\begin{bmatrix} a & b\\ c & d \end{bmatrix},The determinant of A can be found as ad−bc.

Find it.

Input

Input is given from Standard Input in the following format:

a b
c d

Output

Print the answer as an integer.

Samples1

Sample Input 1

1 2
3 4

Sample Output 1

-2

Explaination

The determinant of \begin{bmatrix} 1 &2 \\ 3 &4 \end{bmatrix}=1\times 4-2\times 3=-2.

Samples2

Sample Input 2

0 -1
1 0

Sample Output 2

1

Samples3

Sample Input 3

100 100
100 100

Sample Output 3

0

Constraints

  • All values in input are integers.
  • −100≤a,b,c,d≤100

题解报告

题目翻译

给一个二阶矩阵,求矩阵的行列式(determinant)。

题目分析

ABC 的 A 题还是一如既往的水。本题即使没有学过线性代数也能做,因为题目直接告诉你怎么求了。

数据范围估计

根据题目提供的数据范围,可知 a*c-b*d 的最大值为 100*100-100*(-100)=10000+10000=20000,也就是 2e4。用 int 肯定够了。

AC 参考代码

//https://atcoder.jp/contests/abc184/tasks/abc184_a
//A - Determinant
#include <bits/stdc++.h>

using namespace std;

//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL

int main() {
#ifndef __LOCAL
    //这部分代码需要提交到OJ,本地调试不使用
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<a*d-b*c<<"\n";

#ifdef __LOCAL
    //这部分代码不需要提交到OJ,本地调试使用
    system("pause");
#endif
    return 0;
}

时间复杂度

O(1)。

空间复杂度

O(1)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值