-
Notifications
You must be signed in to change notification settings - Fork 1
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
1-YIM2UL2ET #3
1-YIM2UL2ET #3
Changes from 2 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 @@ | ||
#include <iostream> | ||
|
||
int main(void) | ||
{ | ||
int n, temp, index, result, up, down; | ||
long long value, tvalue; | ||
int villige[100000] = {0}; | ||
|
||
value = 0; | ||
std::cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
std::cin >> temp; | ||
villige[temp-1]++; | ||
value += temp-1; | ||
} | ||
Comment on lines
+11
to
+15
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. βοΈ villigeμ κ°μ΄ 0μ΄λ©΄ λμ΄κ°κ² μ½λκ° μμ±λμ΄μλλ° μ§μ μμΉ(μ λ ₯κ°)μ listμ λ΄κ³ , μ΄λ₯Ό μ λ ¬νμ¬ μ¬μ©νλ λ°©λ²λ νλ² μκ°ν΄λ³΄μ ¨μΌλ©΄ μ’κ² μ΅λλ€.
|
||
|
||
result = 1, index = 0, up = n - villige[0], down = villige[0], tvalue = value; | ||
// tvalue: μμ value, up: λ΄μΌν μ§μ μ, down: μ§κΈκΉμ§ λ΄μ¨ μ§μ μ | ||
|
||
for (int i = 1; i < 100000; i++) { // λ§μ λμ보기 | ||
if (villige[i] == 0) continue; // i+1λ²μ§Έ μμΉμ μ§μ΄ μμΌλ©΄ λ€μ μμΉλ‘ μ΄λ | ||
|
||
tvalue += down * (i - index); | ||
tvalue -= up * (i - index); | ||
down += villige[i]; | ||
up -= villige[i]; | ||
|
||
if (tvalue < value) { // μ§κΈ κ³μ°ν valueκ° μ μ₯νλ valueλ³΄λ€ μμΌλ©΄ | ||
value = tvalue; // μ§κΈ κ³μ°ν valueκ° μ μ₯. | ||
result = i+1; // μ λ΅μΌλ‘ i+1λ²μ§Έ μμΉ μ μ₯ | ||
} | ||
index = i; // μ΅κ·Ό λ΄€λ μ§μ μμΉλ₯Ό κΈ°μ΅νκΈ° | ||
} | ||
|
||
std::cout << result; | ||
return 0; | ||
} |
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.
listλ μ’μ§λ§ vectorλ₯Ό μ¬μ©ν΄λ³΄μλ κ²λ μ’μ κ² κ°μ΅λλ€ γ γ
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.
vectorλ λ°λ°μΌλ‘ μ¬μ©νκ³ μκΈ΄ νλ° νμ€ν vectorκ° cpp 곡λΆνλ©΄ ν μλ‘ μ₯μ μ΄ λ λ§λλΌκ΅¬μ©, μμΌλ‘ μμ£Ό μ΄μ©ν΄λ³΄κ² μ΅λλ€!