SDUT 2562 相似三角形 JAVA

该博客介绍了如何使用Java解决SDUT 2562问题,即根据两个三角形的边长判断它们是否相似。内容包括问题描述、输入输出格式,并给出了样例输入和输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

相似三角形

Time Limit: 1000MS  Memory Limit: 65536KB
Problem Description

给出两个三角形的三条边,判断是否相似。

Input

多组数据,给出6正个整数,a1,b1,c1,a2,b2,c2,分别代表两个三角形。(边长小于100且无序

Output

如果相似输出YES,如果不相似输出NO,如果三边组不成三角形也输出NO。

Example Input
1 2 3 2 4 6
3 4 5 6 8 10
3 4 5 7 8 10
Example Output
NO
YES

NO

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int a1 = sc.nextInt();
			int a2 = sc.nextInt();
			int a3 = sc.nextInt();
			int b1 = sc.nextInt();
			int b2 = sc.nextInt();
			int b3 = sc.nextInt();
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
			}
			if (a1 < a3) {
				int t = a1;
				a1 = a3;
				a3 = t;
			}
			if (a2 < a3) {
				int t = a2;
				a2 = a3;
				a3 = t;
			}
			if (b1 < b2) {
				int t = b1;
				b1 = b2;
				b2 = t;
			}
			if (b1 < b3) {
				int t = b1;
				b1 = b3;
				b3 = t;
			}
			if (b2 < b3) {
				int t = b2;
				b2 = b3;
				b3 = t;
			}
			if (a3 + a2 <= a1 || b3 + b2 <= b1) {
				System.out.println("NO");
			} else {
				if (a1 > b1) {
					int x = a1 % b1;
					int y = a2 % b2;
					int z = a3 % b3;
					if (x == y && x == z && y == z) {
						System.out.println("YES");
					} else {
						System.out.println("NO");
					}
				} else {
					int x = b1 % a1;
					int y = b2 % a2;
					int z = b3 % a3;
					if (x == y && x == z && y == z) {
						System.out.println("YES");
					} else {
						System.out.println("NO");
					}
				}
			}
		}
		sc.close();
	}
}


### 关于 SDUT 编译原理 OJ 的 JAVA 题目及解答 #### 行列式的计算 在解决行列式计算问题时,可以采用递归的方式实现。以下是基于 Java 实现的一个简单例子: ```java import java.util.Scanner; public class DeterminantCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); double[][] matrix = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { matrix[i][j] = scanner.nextDouble(); } } System.out.println(calculateDeterminant(matrix)); } private static double calculateDeterminant(double[][] matrix) { int size = matrix.length; if (size == 1) return matrix[0][0]; // 基础情况 if (size == 2) { // 小矩阵优化 return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]; } double determinant = 0; for (int col = 0; col < size; col++) { double[][] subMatrix = createSubMatrix(matrix, 0, col); // 创建子矩阵 determinant += Math.pow(-1, col) * matrix[0][col] * calculateDeterminant(subMatrix); } return determinant; } private static double[][] createSubMatrix(double[][] original, int excludeRow, int excludeCol) { int size = original.length - 1; double[][] result = new double[size][size]; for (int row = 0, newRow = 0; row < original.length; row++) { if (row != excludeRow) { for (int col = 0, newCol = 0; col < original[row].length; col++) { if (col != excludeCol) { result[newRow][newCol++] = original[row][col]; } } newRow++; } } return result; } } ``` 上述代码实现了通过递归方式求解任意大小方阵的行列式[^1]。 --- #### 异步编程与 Task 处理 对于涉及异步操作的任务处理,在 C# 中可以通过 `Task` 和 `async/await` 来简化复杂逻辑。然而,在 Java 中类似的机制可通过 CompletableFuture 或者线程池来模拟。以下是一个简单的示例展示如何使用 `CompletableFuture` 进行异步任务管理: ```java import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class AsyncExample { public static void main(String[] args) throws ExecutionException, InterruptedException { CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> { try { Thread.sleep(2000); // 模拟耗时操作 } catch (InterruptedException e) { throw new RuntimeException(e); } return 42; }); Integer result = future.get(); // 获取结果并阻塞当前线程直到完成 System.out.println(result); } } ``` 此代码片段展示了如何利用 `CompletableFuture` 执行后台任务,并等待其执行完毕后再继续主线程的工作流程[^3]。 --- #### JavaScript 初学者指南 虽然本问题是关于 Java 及其相关技术栈的应用场景讨论,但值得一提的是,《JavaScript和jQuery实战手册》也提供了丰富的前端开发技巧。例如,编写第一个 JavaScript 程序通常从基本语法入手,如下所示: ```javascript // 输出 Hello World 至控制台 console.log("Hello World"); // 定义变量并打印到页面 let message = "Welcome to the world of programming!"; document.write(message); ``` 这些基础概念同样适用于理解其他高级特性以及跨平台框架集成的知识体系构建过程[^2]。 --- ### 总结 以上分别介绍了针对行列式计算、异步任务管理和初学阶段脚本语言入门等内容的具体实践案例分析。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值