题目相关
题目链接
AtCoder Beginner Contest 184 A 题,https://atcoder.jp/contests/abc184/tasks/abc184_a。
Problem Statement
Given is a 2×2 matrix ,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 .
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)。