-
Notifications
You must be signed in to change notification settings - Fork 0
[브루트포스] 9월 27일 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uBE0C\uB8E8\uD2B8\uD3EC\uC2A4"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // | ||
| // Created by LG on 2021-09-26. | ||
| // | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int triangle(int t, int* tri){ | ||
|
|
||
| for(int i=0; i<45; i++){ | ||
| for(int j=0; j<45; j++){ | ||
| for(int k=0; k<45; k++){ | ||
| if(tri[i] + tri[j] + tri[k] == t) | ||
| return 1; | ||
| } | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
|
|
||
| int start = 1; | ||
| int tri[45]; | ||
| for(int i=2; i<47; i++){ | ||
| tri[i-2] = start; | ||
| start += i; | ||
| } | ||
|
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3. n까지의 합이라는 걸 활용해서 삼각수 잘 구해주셨어요! 👍👍👍 tri[1] = 1을 넣고, i를 지금처럼 2부터 tri[i] += tri[i-1] + i 로 구현하면 코드가 더 깔끔해질 것 같아요! |
||
|
|
||
| for(int i=0; i<n; i++){ | ||
| int t; | ||
| cin >> t; | ||
| cout << triangle(t, tri) << '\n'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| void moveBelt(vector<int> &durab, int &up, int &down, int n){ | ||
| if(up == 0) | ||
| up = 2*n-1; | ||
| else | ||
| up--; | ||
| if(down == 0) | ||
| down = 2*n-1; | ||
| else | ||
| down--; | ||
| } | ||
|
|
||
| void moveRobot(vector<int> &durab, int up, int down, vector<bool> &robot, int n){ | ||
| if(down>up){ | ||
| for(int i=down-1; i>up; i--){ | ||
| if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ | ||
| robot[i] = false; | ||
| robot[i+1] = true; | ||
| durab[i+1]--; | ||
| } | ||
| robot[down] = false; | ||
| } | ||
| } | ||
| else if(down<up){ | ||
| for(int i=down-1; i>=0; i--){ | ||
| if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ | ||
| robot[i] = false; | ||
| robot[i+1] = true; | ||
| durab[i+1]--; | ||
| } | ||
| robot[down] = false; | ||
| } | ||
| for(int i=2*n-1; i>up; i--){ | ||
| if(i==2*n-1){ | ||
| if(durab[0] > 0 && robot[i] && !robot[0]){ | ||
| robot[i] = false; | ||
| robot[0] = true; | ||
| durab[0]--; | ||
| } | ||
| } | ||
| else if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ | ||
| robot[i] = false; | ||
| robot[i+1] = true; | ||
| durab[i+1]--; | ||
| } | ||
| robot[down] = false; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+17
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p2. 같은 연산이 많이 중복되고 있네요!! 지금 up, down 관계가 여러 경우가 있어서 이렇게 해 주신 것 같아요. 하지만 이 부분은 하나의 반복문으로 합칠 수 있어요. moveBelt 함수에서 인덱스를 관리해주신 것처럼 접근할 수 있지 않을까요? 반복문은 꼭 for문만 있는 건 아니죠. |
||
|
|
||
| int main(){ | ||
| int n, k, count = 1; | ||
| cin >> n >> k; | ||
|
|
||
| int up = 0, down = n-1; | ||
| vector<bool> robot(2*n, false); //로봇 유무 | ||
| vector<int> durab(2*n, 0); //내구도 | ||
|
|
||
| //입력 | ||
| for(int i=0; i<2*n; i++){ | ||
| cin >> durab[i]; | ||
| } | ||
|
|
||
| while(true){ | ||
| //1. 내리는 위치와 올리는 위치 옮김 | ||
| moveBelt(durab, up, down, n); | ||
| robot[down] = false; //내리는 위치 로봇 바로 내림. | ||
|
|
||
| //2. 이동 가능한 로봇을 이동. | ||
| moveRobot(durab, up, down, robot, n); | ||
|
|
||
| //3. 올리는 위치에 올림 | ||
| if(durab[up] != 0){ | ||
| robot[up] = true; | ||
| durab[up]--; | ||
| } | ||
|
|
||
| //4. 내구도 0인 칸 세기 | ||
| int zero = 0; | ||
| for(int i=0; i<2*n; i++){ | ||
| if(durab[i] <= 0){ | ||
| zero++; | ||
| } | ||
| } | ||
|
|
||
| //종료 조건 | ||
| if(zero >= k){ | ||
| cout << count; | ||
| break; | ||
| } | ||
|
|
||
| count++; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #include <iostream> | ||
| #include <algorithm> | ||
| #include <cmath> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
|
|
||
| double sum = 0; //float은 틀린다. | ||
| int max = -4000, min = 4000; | ||
| int mid[n]; | ||
| int mode[8001] = {0, }; | ||
|
|
||
| for(int i=0; i<n; i++){ | ||
| int t; | ||
| cin >> t; | ||
| sum += t; | ||
| if(t > max) | ||
| max = t; | ||
| if(t < min) | ||
| min = t; | ||
| mid[i] = t; | ||
|
Comment on lines
+20
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3. 아래서 mid배열의 정렬이 이루어지네요! 그럼 꼭 max, min값 따로 변수로 구해야 할까요? |
||
| mode[t+4000]++; | ||
| } | ||
|
|
||
| cout << round(double(sum/n)) << '\n'; | ||
|
|
||
| sort(mid, mid+n); | ||
| cout << mid[n/2] << '\n'; | ||
|
|
||
| int k = -1; | ||
| int index = 0, count = 0; | ||
| for(int i=0; i<8001; i++){ | ||
| if(mode[i] > k){ | ||
| k = mode[i]; | ||
| index = i; | ||
| count = 0; | ||
| } | ||
| else if(mode[i] == k && count<1){ | ||
| count++; | ||
| index = i; | ||
| } | ||
| } | ||
|
Comment on lines
+35
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍 |
||
| cout << index-4000 << '\n'; | ||
|
|
||
| cout << max-min; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main() { | ||
| int r, b; | ||
| cin >> r >> b; | ||
| int area = r + b; | ||
|
|
||
| int w=0, l=0; | ||
| for(int i=1; i<area/2; i++){ | ||
| if(area%i == 0){ | ||
| w = i; | ||
| l = area/i; | ||
| } | ||
| int temp = (w-1)*2+(l-1)*2; | ||
| if(temp == r && area-temp == b){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p2. 앞의 조건을 만족시킨다면, 뒤의 조건은 무조건 어떻게 되나요? |
||
| cout << max(w, l) << ' ' << min(w, l); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // | ||
| // Created by LG on 2021-09-27. | ||
| // | ||
| #include <iostream> | ||
| #include <map> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int score(int n, map<string, int> answer, vector<string> hyunwoo){ | ||
| int count = 0; | ||
| for(int i=0; i<n; i++){ | ||
| for(int j=i+1; j<n; j++){ | ||
| if(answer[hyunwoo[i]] < answer[hyunwoo[j]]){ | ||
| count++; | ||
| } | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| int main(){ | ||
| int n; | ||
| cin >> n; | ||
|
|
||
| map<string, int> answer; | ||
| for(int i=0; i<n; i++){ | ||
| string s; | ||
| cin >> s; | ||
| answer.insert(pair<string, int>(s, i)); | ||
| } | ||
|
|
||
| vector<string> hyunwoo(n); | ||
| for(int i=0; i<n; i++){ | ||
| cin >> hyunwoo[i]; | ||
| } | ||
|
|
||
| cout << score(n, answer, hyunwoo) << "/" << n*(n-1)/2; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3. 0 또는 1만 반환하네요! 무슨 자료형이 더 적합할까요?