본문 바로가기
Algorithm/Baekjoon

Baekjoon 20215 Cutting Corners JAVA

by Hunveloper 2022. 5. 5.
728x90
 

20215번: Cutting Corners

A large coffee spill in the warehouse of the Busy Association of Papercutters on Caffeine has stained the corners of all paper in storage. In order to not waste money, it was decided that these dirty corners should be cut off of all pieces of paper. A few

www.acmicpc.net

문제

A large coffee spill in the warehouse of the Busy Association of Papercutters on Caffeine has stained the corners of all paper in storage. In order to not waste money, it was decided that these dirty corners should be cut off of all pieces of paper.

A few members loudly proclaim that cuts should be made diagonally, while other members say that cutting the corner out as a rectangle is the better option. Both parties claim their method is better.

You decide to end this discussion once and for all, telling the rectangle-cutters that their method is slower. You set out to show them the following: given a piece of paper which has a w by  corner that is stained with coffee that needs to be to cut off, how much more effort is it to cut out the whole rectangle compared to cutting along the diagonal?

입력

The input consists of:

  • A line containing two integers w and h (1≤w,h≤100), representing the width and height of the corner respectively.
출력

Output how much longer you have to cut if you cut out a rectangle, compared to cutting along the diagonal. Your answer should have an absolute or relative error of at most 10^-6

풀이

가로, 세로를 자르는 것보다 대각선으로 자르는 것이 빠르다는 것을 증명하는 문제이다.

가로 세로를 더한 값에서 대각선으로 나올 수 있는 값을 빼주면 된다.

Root ( A^2+B^2) 으로 대각선의 길이를 구한다.

코드
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(), b=sc.nextInt();
		System.out.println(a+b-Math.pow(a*a+b*b, 0.5));
	}
}

 

728x90
728x90

댓글