結果
問題 | No.328 きれいな連立方程式 |
ユーザー |
|
提出日時 | 2016-05-02 20:16:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 129 ms / 2,000 ms |
コード長 | 4,070 bytes |
コンパイル時間 | 2,026 ms |
コンパイル使用メモリ | 80,208 KB |
実行使用メモリ | 54,180 KB |
最終ジャッジ日時 | 2024-10-05 02:21:23 |
合計ジャッジ時間 | 7,253 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
package yukicoder;import java.math.BigInteger;import java.util.Scanner;public class Main {public static void main(String[] args)throws Exception{new Main().solve();}void solve(){Scanner sc=new Scanner(System.in);double c1=sc.nextDouble();double c2=sc.nextDouble();double c3=sc.nextDouble();double c4=sc.nextDouble();double[][] v1={{c3},{c4}};double[][] A={{c2,-c1},{c3,-c2}};double[][] v2=MtPrd(ReMt(A),v1);double a=v2[0][0];double b=v2[1][0];if(a*a-4*b>=0){System.out.println("R");}else{System.out.println("I");}}//行列の引き算 A-Bdouble[][] MtSbtr(double[][] A,double[][] B){return MtSum(A,Mtce(-1,B));}//行列の定数倍 kAdouble[][] Mtce(double k,double[][] A){double[][] B=new double[A.length][A[0].length];for(int i=0;i<A.length;i++){for(int j=0;j<A[0].length;j++){B[i][j]=k*A[i][j];}}return B;}//転置行列(transposed matrix)double[][] TpMt(double[][] A){double[][] B=new double[A[0].length][A.length];for(int i=0;i<A[0].length;i++){for(int j=0;j<A.length;j++){B[i][j]=A[j][i];}}return B;}//ABCdouble[][] MtPrd(double[][] A,double[][] B,double[][] C){return MtPrd(MtPrd(A,B),C);}//ABCDdouble[][] MtPrd(double[][] A,double[][] B,double[][] C,double[][] D){return MtPrd(MtPrd(A,B,C),D);}//ABdouble[][] MtPrd(double[][] A,double[][] B){double[][] C=new double[A.length][B[0].length];for(int i=0;i<A.length;i++){for(int j=0;j<B[0].length;j++){for(int k=0;k<A[0].length;k++){C[i][j]+=A[i][k]*B[k][j];}}}return C;}long[][] MtPrd(long[][] A,long[][] B){long[][] C=new long[A.length][B[0].length];for(int i=0;i<A.length;i++){for(int j=0;j<B[0].length;j++){for(int k=0;k<A[0].length;k++){C[i][j]+=A[i][k]*B[k][j];}}}return C;}//行列の和;A+Bdouble[][] MtSum(double[][] A,double[][] B){double[][] C=new double[A.length][A[0].length];for(int i=0;i<A.length;i++){for(int j=0;j<A[0].length;j++){C[i][j]=A[i][j]+B[i][j];}}return C;}//2進数に変換;convert to binaryBigInteger bi(int n){BigInteger b=new BigInteger("0");BigInteger digit=new BigInteger("10");for(int i=0;n!=0;i++){if(n%2==0){n/=2;}else{n-=1;n/=2;b=b.add(digit.pow(i));}}return b;}//行列のN乗;R=A^nlong[][] MtPow(int n,long[][] A){BigInteger b=new BigInteger("0");b=bi(n);long[][] B=new long[A.length][A[0].length];for(int i=0;i<A.length;i++){B[i][i]=1;}while(b.compareTo(BigInteger.valueOf(1))>=0){if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))==0){B=MtPrd(A,B);b=b.subtract(BigInteger.valueOf(1));b=b.divide(BigInteger.valueOf(10));}else if((b.remainder(BigInteger.valueOf(10)).compareTo(BigInteger.valueOf(1)))!=0){b=b.divide(BigInteger.valueOf(10));}A=MtPrd(A,A);}return B;}//行列式;detA(Aが正方行列であることを仮定)double detMt(double[][] A){double sum=0;if(A.length==1||A[0].length==1){return A[0][0];}else{for(int j=0;j<A.length;j++){sum+=Math.pow(-1, j)*A[j][0]*detMt(subMt(j+1,0+1,A));}return sum;}}//i行、j列を除いた小行列を出力double[][] subMt(int i,int j,double[][] A){double[][] B=new double[A[0].length-1][A.length-1];for(int k=0;k<A[0].length-1;k++){for(int l=0;l<A.length-1;l++){int kk=k;int ll=l;if(k>=i-1){kk++ ;}if(l>=j-1){ll++;}B[k][l]=A[kk][ll];}}return B;}void showMt(double[][] A){for(int i=0;i<A.length;i++){for(int j=0;j<A[0].length;j++){System.out.print(A[i][j]+" ");}System.out.println();}}//逆行列を求める。double[][] ReMt(double[][] A){double[][] B=new double[A.length][A[0].length];double detA=detMt(A);for(int i=0;i<A.length;i++){for(int j=0;j<A[0].length;j++){B[i][j]=Math.pow(-1,i+j)*detMt(subMt(j+1,i+1,A))/detA;}}return B;}}