-
Notifications
You must be signed in to change notification settings - Fork 9
[이지영] 17주차 20055번 과제 제출합니다. #124
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
Open
gamjalee
wants to merge
1
commit into
kth990303:main
Choose a base branch
from
gamjalee:20055_gamjalee
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include<iostream> | ||
| #include<algorithm> | ||
| using namespace std; | ||
| struct belt{ | ||
| int num; | ||
| int robot; | ||
| }; | ||
| belt map[201], tmpp[201]; | ||
| int cnt=0, N, K, x; | ||
| int main(){ | ||
| cin >> N >> K; | ||
| for(int i=1; i<=2*N; i++){ | ||
| cin >> map[i].num; | ||
| map[i].robot = 0; | ||
| } | ||
| int flag=1; | ||
| while(true){ | ||
| //1. 벨트가 각 칸 위에 있는 로봇과 함께 한 칸 회전한다. | ||
| tmpp[1] = map[2*N]; | ||
| for(int i=2; i<=2*N; i++) tmpp[i] = map[i-1]; | ||
| for(int i=1; i<=2*N; i++) map[i] = tmpp[i]; | ||
| if(map[N].robot) map[N].robot = 0; | ||
|
|
||
| //2. 가장 먼저 벨트에 올라간 로봇부터, 벨트가 회전하는 방향으로 한 칸 이동할 수 있다면 이동한다. 만약 이동할 수 없다면 가만히 있는다. | ||
| //로봇이 이동하기 위해서는 이동하려는 칸에 로봇이 없으며, 그 칸의 내구도가 1 이상 남아 있어야 한다. | ||
| for(int i=N-1; i>=1; i--) { | ||
| if(map[i].robot) { | ||
| if(!map[i+1].robot && map[i+1].num >= 1) { | ||
| map[i+1].robot = map[i].robot; | ||
| map[i+1].num--; | ||
| if(map[i+1].num == 0) cnt++; | ||
| map[i].robot = 0; | ||
| } | ||
| } | ||
| } | ||
| if(map[N].robot) map[N].robot = 0; | ||
|
|
||
| //3. 올리는 위치에 있는 칸의 내구도가 0이 아니면 올리는 위치에 로봇을 올린다. | ||
| if(map[1].num >= 1 && !map[1].robot) { | ||
| map[1].robot = 1; | ||
| map[1].num--; | ||
| if(map[1].num == 0) cnt++; | ||
| } | ||
|
|
||
| //4. 내구도가 0인 칸의 개수가 K개 이상이라면 과정을 종료한다. 그렇지 않다면 1번으로 돌아간다. | ||
| if(cnt >= K) { | ||
| cout << flag; | ||
| return 0; | ||
| } | ||
| flag +=1; | ||
| } | ||
| return 0; | ||
| } | ||
|
Collaborator
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. 주석이 너무 보기 좋네요 |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
회전을 잘 구현하셨네요