문제

At the Van Abbemuseum of modern and contemporary art in Eindhoven, we always look to present our muses in the most interesting way possible. Sometimes we have our work cut out for us.

Today we are exploring whether we can modify one of our perfectly-square picture frames (such as the one shown in Figure C.1) to include an electrical filament. The purpose of this filament is so that the image can set itself alight at some opportune and hilarious moment—for example, in the middle of a sale by auction.

You will be responsible for buying the filament to run around the entire perimeter of the artwork. How many centimetres will you need to obtain?

Figure C.1: A test subject for the frame.

입력

The input consists of:

  • One line with an integer a (1 ≤ a ≤ 10^18), the area of the image in square centimetres.

출력

Output the total length of filament needed for the frame, in centimetres. Your answer should have an absolute or relative error of at most 10^−6.

예제 입력 1

64

예제 출력 1

32.0

예제 입력 2

1234

예제 출력 2

140.51334456

더보기

Solution

#include<stdio.h>
#include<math.h>

int main(void)
{
	double area;

	scanf("%lf", &area);

	area=sqrt(area);

	printf("%lf\n", 4.0*area);
	return 0;
}
728x90

문제

당신은 학생들의 기초수학 학습을 돕는 소프트웨어를 개발하는 팀의 개발자이다. 당신은 가분수를 대분수(?)로 출력하는 부분을 개발해야 한다. 진분수는 분자가 분모보다 작은 분수이다; 대분수는 정수부를 따로 떼어주고 남는 부분을 진분수로 쓰는 기법이다. 예제로, 27/12는 대분수로 2 3/12이다. 기약분수로 만들지 말아야 한다.(3/12를 1/4로 바꿔 출력하지 마시오.)

입력

한 줄에 걸쳐 한 테스트 케이스가 입력된다. 각각의 테스트 케이스는 [1, 2^31 - 1]범위의 두 정수가 입력된다. 첫 번째 정수는 분자고 두 번째는 분모이다. "0 0" 입력이 들어오는 라인에서 입력을 종료한다.

출력

각 테스트 케이스에 대해 한 줄에 걸쳐 주어진 입력에 맞는 대분수를 공백토큰으로 구분하여 출력하라.

예제 입력 1

27 12
2460000 98400
3 4000
0 0

예제 출력 1

2 3 / 12
25 0 / 98400
0 3 / 4000

더보기

Solution

#include<stdio.h>

int main(void)
{
	int numerator, denominator;

	scanf("%d %d", &numerator, &denominator);

	while(numerator!=0 || denominator!=0)
	{
		printf("%d %d / %d\n", numerator/denominator, numerator%denominator, denominator);
		scanf("%d %d", &numerator, &denominator);
	}

	return 0;
}
728x90

문제

민호는 이산수학 강의를 듣는다.

어느 날 교수님께서 Positive rational numbers are countable에 대해 증명해 주시고, 역시나 과제를 내주셨다. 

양의 유리수는 다음 그림처럼 열거할 수 있다.

첫 번째 유리수는 1/1, 두 번째 유리수는 2/1, 세 번째 유리수는 1/2, 네 번째 유리수는 3/1, 다섯 번째 유리수는 2/2, ... 이다.

1/1, 2/2, 3/3, ... 은 다르게 취급 하는것에 유의하여야 한다.

위 그림처럼 모든 유리수에 순차적으로 번호를 붙였을 때, N번째 유리수를 구하여라.

 과제가 하기 싫은 민호는 컴공과답게 N번째 유리수를 구하는 프로그램을 만들려고 한다.

입력

첫 번째 줄에 양의 정수 N이 주어진다. (1 ≤ N ≤ 1000)

출력

N번째 유리수가 a/b일 때, 분자 a, 분모 b를 공백으로 구분하여 a, b를 출력하여라.

예제 입력 1

1

예제 출력 1

1 1

예제 입력 2

2

예제 출력 2

2 1

예제 입력 3

5

예제 출력 3

2 2

힌트

과제가 하기 싫었던 민호는 실제로 이 과제를 프로그램으로 만들어 식을 유도했다고 한다.


더보기

Solution

#include<stdio.h>
#include<stdbool.h>

int main(void)
{
	int N;
	bool solved=false;

	scanf("%d", &N);

	for(int sum=2;!solved;sum++)
		for(int b=1;!solved&&b<sum;b++,N--)
			if(N==1)
			{
				solved=true;
				printf("%d %d\n", sum-b, b);
			}

	return 0;
}
728x90

문제

You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.

Given the ages of the youngest and middle children, what is the age of the oldest child?

입력

The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 ≤ Y ≤ 50). The second line is the age M of the middle child (Y ≤ M ≤ 50).

출력

The output will be the age of the oldest child.

예제 입력 1

12
15

예제 출력 1

18

더보기

Solution

#include<stdio.h>

int main(void)
{
	int Y, M;

	scanf("%d", &Y);
	scanf("%d", &M);
	printf("%d\n", 2*M-Y);

	return 0;
}
728x90

문제

꿍은 오늘 학교에서 삼각형에 대해 배웠다. 삼각형은 변의 길이에 따라 다음과 같이 분류될 수 있다.

  • 정삼각형(equilateral triangle)은 모든 변의 길이가 같다. 각 역시 60도로 모두 같다.
  • 이등변삼각형(isosceles triangle)은 두 개의 변의 길이가 같다. 각 역시 두 개의 각의 크기가 같다.
  • 부등변삼각형(scalene triangle)은 모든 변의 길이가 같지 않다. 각 역시 모두 다르다. 몇몇 부등변삼각형의 경우 직각삼각형이다.

수학선생님이 삼각형의 세 변의 길이를 가지고 삼각형을 분류하라는 숙제를 내줬는데 꿍은 정말 놀고싶다. 꿍이 놀수있도록 여러분이 도와주어라.

입력

입력의 첫 줄에는 테스트케이스의 개수 T(1 <= T <= 100)가 주어진다. 다음 T줄에는 각 줄에 삼각형의 세 변을 나타내는 3개의 정수 A,B,C(1 <= A,B,C <= 1,000,000)가 주어진다.

출력

각 테스트 케이스에 대해 삼각형이 “equilateral”, “isosceles”, “scalene” 타입 중 어느 타입에 속하는지 출력한다. 만약 주어진 세 변의 길이로 삼각형이 만들어지지 않을경우, “invalid!”를 출력한다.

예제 입력 1

2
3 3 4
6 4 2

예제 출력 1

Case #1: isosceles
Case #2: invalid!

더보기

Solution

#include<stdio.h>

int main(void)
{
	int T, triangle[3];

	scanf("%d", &T);

	for(int t=1;t<=T;t++)
	{
		for(int i=0;i<3;i++)
			scanf("%d", &triangle[i]);

		for(int i=0;i<2;i++)
			for(int j=i+1;j<3;j++)
				if(triangle[i]>triangle[j])
				{
					int temp=triangle[i];
					triangle[i]=triangle[j];
					triangle[j]=temp;
				}

		printf("Case #%d: %s\n", t, triangle[0]+triangle[1]<=triangle[2]?"invalid!":triangle[0]==triangle[1]&&triangle[1]==triangle[2]?"equilateral":triangle[0]==triangle[1]||triangle[1]==triangle[2]?"isosceles":"scalene");
	}

	return 0;
}
728x90

문제

앞 면에 O와 X가 적혀있는 카드 N개가 있다. N개의 카드 중 M개의 카드의 앞면에는 O가 한 개 적혀있고, 나머지 N-M개의 카드의 앞면에는 X가 한 개 적혀있다. 카드의 뒷 면은 두 종류의 카드 모두 같은 모양이라 구분할 수 없다.

카드의 뒷 면에 O나 X를 하나씩 적으려고 한다. 이 때, O는 K개, X는 N-K개 적으려고 한다.

앞 면과 뒷 면에 같은 모양이 적혀있는 카드의 최대 개수를 구하는 프로그램을 작성하시오.

입력

첫째 줄에 N, M, K가 주어진다. (1 ≤ N ≤ 1,000,000, 0 ≤ M, K ≤ N)

출력

첫째 줄에 앞 면과 뒷 면에 같은 모양이 적혀있는 카드의 최대 개수를 출력한다.

예제 입력 1

4 3 2

예제 출력 1

3

예제 입력 2

10 0 10

예제 출력 2

0

예제 입력 3

5 3 3

예제 출력 3

5

예제 입력 4

7 5 2

예제 출력 4

4

더보기

Solution

#include<stdio.h>

int main(void)
{
	int N, M, K;

	scanf("%d %d %d", &N, &M, &K);
	printf("%d\n", (M>K?K:M)+(N-M>N-K?N-K:N-M));

	return 0;
}
728x90

문제

You record all of the scoring activity at a basketball game. Points are scored by a 3-point shot, a 2-point field goal, or a 1-point free throw.

You know the number of each of these types of scoring for the two teams: the Apples and the Bananas. Your job is to determine which team won, or if the game ended in a tie.

입력

The first three lines of input describe the scoring of the Apples, and the next three lines of input describe the scoring of the Bananas. For each team, the first line contains the number of successful 3-point shots, the second line contains the number of successful 2-point field goals, and the third line contains the number of successful 1-point free throws. Each number will be an integer between 0 and 100, inclusive.

출력

The output will be a single character. If the Apples scored more points than the Bananas, output 'A'. If the Bananas scored more points than the Apples, output 'B'. Otherwise, output 'T', to indicate a tie.

예제 입력 1

10
3
7
8
9
6

예제 출력 1

B

The Apples scored 10⋅3+3⋅2+7⋅1 = 43 points and the Bananas scored 8⋅3+9⋅2+6⋅1 = 48 points, and thus the Bananas won.

예제 입력 2

7
3
0
6
4
1

예제 출력 2

T

The Apples scored 7⋅3+3⋅2+0⋅1 = 27 points and the Bananas scored 6⋅3+4⋅2+1⋅1 = 27 points, and thus it was a tie game.


더보기

Solution

#include<stdio.h>

int main(void)
{
	int Apples=0, Bananas=0, score;

	for(int i=3;i>0;i--)
	{
		scanf("%d", &score);
		Apples+=i*score;
	}
	for(int i=3;i>0;i--)
	{
		scanf("%d", &score);
		Bananas+=i*score;
	}

	printf("%c\n", Apples>Bananas?'A':Apples<Bananas?'B':'T');
	return 0;
}
728x90

문제

연속한 소수 p와 p+n이 있을 때, 그 사이에 있는 n-1개의 합성수(소수나 1이 아닌 양의 정수)는 길이가 n인 소수 사이 수열라고 부른다.

양의 정수 k가 주어졌을 때, k를 포함하는 소수 사이 수열의 길이를 구하는 프로그램을 작성하시오. k를 포함하는 소수 사이 수열이 없을 때는 길이가 0이다.

예를 들어, 소수 23과 29의 소수 사이 수열은 {24, 25, 26, 27, 28}이고, 길이는 6이다.

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다. 테스트 케이스는 한 줄로 이루어져 있고, 한 줄에 정수 k가 주어진다. 각각의 정수는 1보다 크고, 100000번째 소수(1299709)와 작거나 같다.

출력

각각의 테스트 케이스에 대해서 k가 합성수라면 k를 포함하는 소수 사이 수열의 길이를 출력한다. 그렇지 않으면 0을 출력한다.

예제 입력 1

5
10
11
27
2
492170

예제 출력 1

4
0
6
0
114

더보기

Solution

#include<stdio.h>
#include<stdbool.h>

bool isPrime(int N)
{
	if(N<2)
		return false;
	else if(N==2)
		return true;
	else if(N%2==0)
		return false;
	else
		for(int n=3;n*n<=N;n+=2)
			if(N%n==0)
				return false;
	return true;
}

int main(void)
{
	int T, small, big, k;

	scanf("%d", &T);

	for(int t=0;t<T;t++)
	{
		scanf("%d", &k);

		if(isPrime(k))
			printf("0\n");
		else
		{
			for(big=k+1;!isPrime(big);big++);
			for(small=k-1;small>0&&!isPrime(small);small--);

			printf("%d\n", small!=0?big-small:0);
		}
	}

	return 0;
}
728x90

+ Recent posts