백준/백준 단계별 문제풀이 74

백준 1002번 (C++)

www.acmicpc.net/problem/1002 1002번: 터렛 각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다. www.acmicpc.net #include #include using namespace std; void swap(double *r1, double *r2) { double temp = *r1; *r1 = *r2; *r2 = temp; } int main() { int t; int x1,x2,y1,y2; double r1,r2; double distance; cin>>t; while(t-- > 0) { cin>>x1>>y1>>r1>>x2>>y2>>r2; distance = sqrt(pow(..

백준 4153번 (C++)

www.acmicpc.net/problem/4153 4153번: 직각삼각형 입력은 여러개의 테스트케이스로 주어지며 마지막줄에는 0 0 0이 입력된다. 각 테스트케이스는 모두 30,000보다 작은 양의 정수로 주어지며, 각 입력은 변의 길이를 의미한다. www.acmicpc.net #include #include using namespace std; int main() { int array[3]; bool end = false; cin>>array[0]>>array[1]>>array[2]; while(!end) { sort(array,array+3); if(array[2]*array[2] == array[0]*array[0] + array[1]*array[1]) { coutarray[1]>>array[2]..

백준 1085번 (C++)

www.acmicpc.net/problem/1085 1085번: 직사각형에서 탈출 첫째 줄에 x y w h가 주어진다. w와 h는 1,000보다 작거나 같은 자연수이고, x는 1보다 크거나 같고, w-1보다 작거나 같은 자연수이고, y는 1보다 크거나 같고, h-1보다 작거나 같은 자연수이다. www.acmicpc.net #include using namespace std; int main() { int x,y,w,h; int width1, width2, hight1, hight2; int result_w, result_h; cin>>x>>y>>w>>h; width1 = x; hight1 = y; width2 = w-x; hight2 = h-y; if(width1 < width2) result_w = w..

백준 9020번 (C++)

www.acmicpc.net/problem/9020 9020번: 골드바흐의 추측 1보다 큰 자연수 중에서 1과 자기 자신을 제외한 약수가 없는 자연수를 소수라고 한다. 예를 들어, 5는 1과 5를 제외한 약수가 없기 때문에 소수이다. 하지만, 6은 6 = 2 × 3 이기 때문에 소수가 아 www.acmicpc.net #include using namespace std; int main() { int n, input; int temp; int array[10001] = {0}; int result1, result2; int term; array[1] = -1; cin>>n; while(n-- > 0) { cin>>input; temp = input/2; for(int i=2; i

백준 4948번 (C++)

www.acmicpc.net/problem/4948 4948번: 베르트랑 공준 베르트랑 공준은 임의의 자연수 n에 대하여, n보다 크고, 2n보다 작거나 같은 소수는 적어도 하나 존재한다는 내용을 담고 있다. 이 명제는 조제프 베르트랑이 1845년에 추측했고, 파프누티 체비쇼 www.acmicpc.net #include using namespace std; int main() { int n; int count = 0; int array[246913]; array[1] = -1; cin>>n; while(n != 0) { for(int i=2; i

백준 1011번 (C++)

www.acmicpc.net/problem/1011 1011번: Fly me to the Alpha Centauri 우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을 내려 놓은 지 23년이 지난 지금, 세계 최연소 ASNA 우주 비행�� www.acmicpc.net #include #include using namespace std; int main() { int t; unsigned int x, y, term; int afterMath; int result = 0; int temp; cin>>t; while(t-- > 0) { cin>>x>>y; term = y-x; afterMath = sqrt(term); if(term..

백준 10250번 (C++)

www.acmicpc.net/problem/10250 10250번: ACM 호텔 문제 ACM 호텔 매니저 지우는 손님이 도착하는 대로 빈 방을 배정하고 있다. 고객 설문조사에 따르면 손님들은 호텔 정문으로부터 걸어서 가장 짧은 거리에 있는 방을 선호한다고 한다. 여러분은 www.acmicpc.net #include using namespace std; int main() { int t; int hight, width, n; int h, w; int temp; int term; int result; cin>>t; for(int i=0; i>hight>>width>>n; h = hight; w = n / hight; temp = h * w; term = n - temp; if(term == 0) { resu..

백준 2869번 (C++)

www.acmicpc.net/problem/2869 2869번: 달팽이는 올라가고 싶다 문제 땅 위에 달팽이가 있다. 이 달팽이는 높이가 V미터인 나무 막대를 올라갈 것이다. 달팽이는 낮에 A미터 올라갈 수 있다. 하지만, 밤에 잠을 자는 동안 B미터 미끄러진다. 또, 정상에 올라간 �� www.acmicpc.net #include using namespace std; int main() { int a,b,v; int days = 0; int term; cin>>a>>b>>v; term = a-b; if((v-a)%term == 0) days = (v-a) / term + 1; else days = (v-a) / term + 2; cout= v 이다 정리를 하면 days >= (v-a) / term 이다..

백준 1193번 (C++)

www.acmicpc.net/problem/1193 1193번: 분수찾기 첫째 줄에 X(1 ≤ X ≤ 10,000,000)가 주어진다. www.acmicpc.net #include using namespace std; int main() { int x; int temp = 1; int i = 1; int n = 1,m = 1; cin>>x; while(x > temp) { i++; temp+=i; } if(i%2 == 0) { n = i; m = 1; n = n - (temp-x); m = m + (temp-x); } else { n = 1; m = i; n = n + (temp-x); m = m - (temp-x); } cout i=4) ... 식으로 1부터 차례로 2,3,4를 더한 번째가 대각선 방향..