Ultraviolet A 684-integral determinant (determinant transformation)

Source: Internet
Author: User

Ultraviolet A 684-integral Determinant

Question Link

Question: Give a determinant and find the value.

Train of Thought: Use the column subtraction in linear algebra, and then continuously reduce the order, that is, use the score to write

Code:

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int n = 35; long gcd (long a, long B) {If (! B) return a; return gcd (B, A % B);} long lcm (long a, long B) {A = A/gcd (A, B) * B; if (a <0) A =-A; return a;} struct fraction {long a, B; fraction () {A = 0; B = 1 ;} fraction (long x) {A = x; B = 1;} fraction (long X, long y) {A = x; B = y;} void deal () {If (B <0) {B =-B; A =-A;} long K = gcd (a, B); If (k <0) k =-K; A/= K; B/= K;} fraction operator + (F Raction p) {fraction ans; ans. B = lcm (B, P. b); ans. A = ans. b/B * A + ans. b/P. B * P. a; ans. deal (); Return ans;} fraction operator-(fraction p) {fraction ans; ans. B = lcm (B, P. b); ans. A = ans. b/B * A-ans. b/P. B * P. a; ans. deal (); Return ans;} fraction operator * (fraction p) {fraction ans; ans. A = A * P. a; ans. B = B * P. b; ans. deal (); Return ans;} fraction operator/(fraction p) {fracti On ans; ans. A = A * P. b; ans. B = B * P. a; ans. deal (); Return ans;} void operator = (long x) {A = x; B = 1;} void print () {printf ("% LLD/% LLD \ n", a, B) ;}}; int N; struct Col {fraction R [N];} C [N]; long long solve () {int now = 1; fraction x = 1; for (INT now = 1; now <n; now ++) {int flag = 1; for (INT I = now-1; I <n; I ++) {If (C [I]. R [now-1]. a) {swap (C [now-1], C [I]); if (I! = Now-1) x = x * fraction (-1); flag = 0; break;} If (FLAG) return 0; flag = 1; for (INT I = now; I <n; I ++) {fraction K = C [I]. R [now-1]/C [now-1]. R [now-1]; for (Int J = now-1; j <n; j ++) C [I]. R [J] = C [I]. R [J]-(fraction (k) * C [now-1]. R [J]);} X = x * C [now-1]. R [now-1];} return (x * C [n-1]. R [n-1]). a;} int main () {While (~ Scanf ("% d", & N) {If (n = 0) {printf ("* \ n"); break;} long num; for (INT I = 0; I <n; I ++) {for (Int J = 0; j <n; j ++) {scanf ("% LLD ", & num); C [J]. R [I] = num;} printf ("% LLD \ n", solve ();} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.