-
Notifications
You must be signed in to change notification settings - Fork 0
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
09_백트랙킹 #20
Open
lumiere-on
wants to merge
2
commits into
main
Choose a base branch
from
09_백트랙킹
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.
The head ref may contain hidden characters: "09_\uBC31\uD2B8\uB799\uD0B9"
Open
09_백트랙킹 #20
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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,65 @@ | ||
#include <iostream> | ||
#include <stack> | ||
#include <deque> | ||
|
||
using namespace std; | ||
|
||
int N; | ||
int operand[11]; | ||
int op[4]; | ||
int MIN=1000000001; | ||
int MAX=-1000000001; | ||
|
||
void getResult(int result, int idx){ | ||
if(idx==N){ | ||
if(result>MAX){ | ||
MAX=result; | ||
} | ||
if(result<MIN){ | ||
MIN=result; | ||
} | ||
return; | ||
} | ||
for(int i=0; i<4; i++){ | ||
if(op[i]>0){ | ||
op[i]--; | ||
switch(i){ | ||
case 0:{ | ||
getResult(result+operand[idx], idx+1); | ||
break; | ||
} | ||
case 1:{ | ||
getResult(result-operand[idx], idx+1); | ||
break; | ||
} | ||
case 2:{ | ||
getResult(result*operand[idx], idx+1); | ||
break; | ||
} | ||
case 3:{ | ||
getResult(result/operand[idx], idx+1); | ||
break; | ||
} | ||
} | ||
op[i]++; | ||
|
||
} | ||
} | ||
return; | ||
} | ||
int main(){ | ||
|
||
cin >> N; | ||
|
||
for(int i=0; i<N; i++){ | ||
cin >> operand[i]; | ||
} | ||
for(int j=0; j<4; j++){ | ||
cin >> op[j]; | ||
} | ||
getResult(operand[0], 1); | ||
cout << MAX << "\n"; | ||
cout << MIN << "\n"; | ||
|
||
return 0; | ||
} |
This file contains 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,44 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <set> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
#define MAX 9 | ||
|
||
int N,M; | ||
int input[MAX]; | ||
int arr[MAX]; | ||
set<vector<int>> s; | ||
|
||
void dfs(int k) { | ||
if(k==M) { //끝 | ||
vector<int> v; | ||
for(auto i=0;i<M;i++) | ||
v.push_back(arr[i]); | ||
s.insert(v); | ||
v.clear(); | ||
}else { | ||
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. 이럴때 else를 쓰기보다, |
||
for(auto i=0; i<N;i++) { | ||
arr[k]=input[i]; | ||
dfs(k+1); | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
cin >> N >> M; | ||
|
||
for(int i=0;i<N;i++) | ||
cin >> input[i]; | ||
|
||
sort(input,input+N); | ||
|
||
dfs(0); | ||
|
||
for(auto vector:s) { | ||
for(auto temp:vector) | ||
cout << temp << " "; | ||
cout << "\n"; | ||
} | ||
} |
This file contains 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,37 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
pair<int, int> li[12]; | ||
|
||
int findArea() { // 육각형 모양의 영역 너비를 구하는 함수 | ||
int big_square; //사각형 중 큰 부분 | ||
int small_square; //사각형 중 작은 부분을 의미. | ||
for (int i = 0; i < 9; i++) { //for문을 돌아가며 외부 사각형과 내부 사각형의 너비를 갱신. | ||
if (li[i].first == li[i + 2].first && li[i + 1].first == li[i + 3].first) { // 같은 방향이 한 칸을 건너뛰고 나타나는 형태이면 | ||
big_square = (li[i].second + li[i + 2].second) * (li[i + 1].second + li[i + 3].second); // 전체 사각형 갱신 | ||
small_square = li[i + 2].second * li[i + 1].second; // 작은 사각형(영역이 없는 구역 갱신) | ||
} | ||
} | ||
return big_square - small_square; //큰사각형-작은 사각형을 빼주는 것을 최종 결과값으로 리턴. | ||
} | ||
|
||
int main() { | ||
int k; | ||
cin >> k; //1m2의 넓이에 자라는 참외의 개수 | ||
|
||
int direction, length; | ||
for (int i = 0; i < 6; i++) { | ||
cin >> direction >> length; //방향과 길이를 입력받음. | ||
li[i] = {direction, length}; //입력받은 방향과 길이를 pair로 묶어 배열에 저장. | ||
} | ||
|
||
for (int i = 0; i < 6; i++) { //어디서부터 입력이 들어오는지 모르기 때문에 6개 변을 추가해줌 | ||
li[i + 6] = li[i]; | ||
} | ||
|
||
int area = findArea(); //결과값에 함수의 결과를 할당. | ||
cout << k * area << "\n"; //1m^2에서 자라는 참외의 개수*너비를 곱해준 값이 참외가 자라는 총 개수 | ||
|
||
return 0; | ||
} |
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.
한 가지 피드백을 드린다면,
변하지 않는 값을 상수값으로 정의해서 사용해보세용!