-
Notifications
You must be signed in to change notification settings - Fork 1
8-dohyeondol1 #32
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
8-dohyeondol1 #32
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,42 @@ | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <deque> | ||
| #include <algorithm> | ||
| using namespace std; | ||
|
|
||
| int main() { | ||
| cin.tie(0)->sync_with_stdio(0); | ||
| int N, M; | ||
| cin >> N >> M; | ||
|
|
||
| deque<int> dq; | ||
| for(int i = 1; i <= N; i++) | ||
| dq.push_back(i); | ||
|
Comment on lines
+12
to
+14
Member
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. μμ£Ό μ¬μν ν? μΈλ° #include <numeric>
deque<int> DQ(N);
iota(DQ.begin(), DQ.end(), 1); // 1, 2, 3, ..., N - 1, NμΌλ‘ DQκ° μ±μμ§numeric ν€λμ iotaλΌλ ν¨μκ° μμ΅λλ€. μ΄κ±°λ₯Ό μ¬μ©νλ©΄ λ겨주λ μ«μ(μ¬κΈ°μλ 1)λΆν° 1μ© μ¦κ°νλ κ°μΌλ‘ μ±μμ€λλ€.
Contributor
Author
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. μ€νΈ....!!!!! μ¬μνμ§λ§ μΈμ κ° μ¨λ¨Ήμ ν!! κ°μ¬ν©λλ€ |
||
|
|
||
| vector<int> target(M); | ||
| for(int i = 0; i < M; i++) | ||
| cin >> target[i]; | ||
|
Comment on lines
+16
to
+18
Member
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. μ¬μ€ μ΄ λ¬Έμ λ μ΄λ€ targetκ°μ μ¬μ©ν λ, λ€λ₯Έ targetκ°μ μ νμκ° μκΈ° λλ¬Έμ λ°°μ΄μ 미리 λ€ μ μ₯ν΄λμ§ μμλ λ©λλ€. while(M--)
{
int target; cin >> target;
int index = find(dq.begin(), dq.end(), target[i]) - dq.begin();
...
}μ΄λ° μμΌλ‘ μ€μκ°μΌλ‘ target κ°μ νλμ© λ°μ λλ§λ€ μ°μ°μ μννλλ‘ μ½λλ₯Ό μμ±ν΄λ 무방νμ£ :)
Contributor
Author
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. κ·Έλ λ€μ...; λλ¦ κΉλλ€κ³ κΉμλλ° μ΄μ§ λͺ¨μλλ λ΄
λλ€.. |
||
|
|
||
| int count = 0; | ||
| for(int i = 0; i < M; i++) { | ||
| int index = find(dq.begin(), dq.end(), target[i]) - dq.begin(); | ||
|
|
||
| if(index <= dq.size()/2) { | ||
| while(index--) { | ||
| dq.push_back(dq.front()); | ||
| dq.pop_front(); | ||
| count++; | ||
| } | ||
| } else{ | ||
| int step = dq.size() - index; | ||
| while(step--) { | ||
| dq.push_front(dq.back()); | ||
| dq.pop_back(); | ||
| count++; | ||
| } | ||
| } | ||
| dq.pop_front(); | ||
| } | ||
|
|
||
| cout << count << '\n'; | ||
| } | ||
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.
λ κ°μ λκ²¨μ€ λ κ°λ₯νλ©΄
nullptrμ μ¬μ©ν΄μ£ΌμΈμ©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.
nullptrμ ν¬μΈν°λ₯Ό λͺ νν λνλ΄λκ΅°μ..nullptrμ μ¬μ©νλκ±Έ μ§ν₯ν΄μΌκ² λ€μ₯