8000 Merge pull request #273 from SciEm/1193.cpp · w10gd/basic-algo-lecture@0514bfc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0514bfc

Browse files
Merge pull request encrypted-def#273 from SciEm/1193.cpp
Update 1193.cpp
2 parents 5739c5a + 19d57a2 commit 0514bfc

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

0x12/solutions/1193

18.4 KB
Binary file not shown.

0x12/solutions/1193.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : SciEm
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/4786afbccbb148098938f248823abd35
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
int main() {
88
ios::sync_with_stdio(0);
99
cin.tie(0);
10-
11-
}
10+
11+
int x;
12+
cin >> x;
13+
14+
// x에서 1 2 3 ...을 빼다보면 찾는 수가 i 번째 군의 x 번째 수가 된다.
15+
int i = 1;
16+
while (x > i) {
17+
x -= i;
18+
i++;
19+
}
20+
21+
int nume = x;
22+
int deno = i + 1 - x;
23+
if (i % 2) swap(nume, deno); // 홀수 번째 군의 순서가 문제와 반대이므로 뒤집는다.
24+
cout << nume << '/' << deno;
25+
}
26+
/*
27+
수열을 (1/1) (1/2 2/1) (1/3 2/2 3/1) ... 과 같이 묶으면 i번째 군의 개수는
28+
i개 이고 분자와 분모의 합이 i + 1로 일정함을 알 수 있다.
29+
*/

0 commit comments

Comments
 (0)
0