Gym 100735I Yet another A + B (java大数)

来源:互联网 发布:c语言表示10的n次方 编辑:程序博客网 时间:2024/06/06 14:06

Gym 100735I Yet another A + B


题意:给定a,b,c,问是否能构成x+y=z的式子,a,b,c可以重复使用。


思路:正解应该是高精度模拟……不过我偷懒用java大数了,比敲高精度模板容易多了……


import java.util.*;import java.math.*;public class Main {public static void main(String[] args) {Scanner in=new Scanner(System.in);BigInteger a[]=new BigInteger [3];a[0]=in.nextBigInteger();a[1]=in.nextBigInteger();a[2]=in.nextBigInteger();boolean flag=false;for (int i=0; i<3; ++i)for (int j=0; j<3; ++j)for (int k=0; k<3; ++k)if (a[i].add(a[j]).equals(a[k])) flag=true;if (flag) System.out.println("YES");else System.out.println("NO");in.close();}}

0 0