분류 전체보기

    [Algorithm] bits/stdc++.h 헤더

    #include 해당 헤더안에 모든 표준 라이브러리가 들어가 있음 단 MSVC에는 해당 헤더가 존재하지 않는데 직접 경로에 헤더파일을 추가해놓으면 됨. 참고 https://blog.encrypted.gg/724?category=773649

    [Algorithm] cin/cout 시간초과 방지

    int main(void){ ios::sync_with_stdio(0); cin.tie(0); } scanf/printf와는 다르게 cin/cout에서는 입출력으로 인한 시간초과를 방지하기 위해 반드시 ios::sync_with_stdio(0), cin.tie(0)이라는 두 명령을 실행시켜야 합니다. 두 명령을 실행시키지 않으면 입/출력의 양이 많을 때 시간초과가 발생할 수 있습니다. -ios::sync_with_stdio(0) : C++ stream과 C stream의 sync를 끄는 명령. 따라서 해당 명령어를 입력할 경우 printf와 cout을 함께 쓰면 안됨. cout만 써야함. -cin.tie(0) : cin과 cout이 번갈아 나올 때 마다 flush를 하지 않도록 하는 명령. 채점 환경에서..

    [SW Expert Academy] 2072. 홀수만 더하기

    문제 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QSEhaA5sDFAUq 코드 내가 푼것 #include using namespace std; int main(void) { int n = 0; //number of test cases cin >> n; for (int i = 0; i > tmp; if (tmp % 2 !=0) result += tmp; } cout

    [SW Expert Academy] 2071. 평균값 구하기

    문제 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QRnJqA5cDFAUq 코드 #include #include using namespace std; int main(void) { int result = 0; //result of calculation int n = 0; //number of test cases cin >> n; float* test = new float[n]; //store result for (int i = 0; i > tmp; result += tmp; } ..

    [C++] new/delete 이용한 2차원 배열 동적할당

    1차원 배열 int* arr = new int[x]; 2차원 배열 int** arr = new int*[x]; for(int i = 0; i < x; ++i) arr[i] = new int[y];

    [C++] 소수점 반올림/올림/내림/버림

    출력만 하는 경우 형식 지정자 %.2f 를 사용 ( 몇번째 자리에서 반올림 하냐에 따라 숫자 변경 int main(void) { float myfloat = 37.777779; printf("%.2f", myfloat); } 출력: 37.78 연산을 하는 경우 1) 내림/반올림/올림에 따라 각 각 의 floor() / ceil() / floor() 함수 사용 #include float val = 37.777779; float rounded_down = floor(val); /* 내림: 37 */ float nearest = floor(val + 0.5); /* 반올림: 38 */ float rounded_up = ceil(val); /* 올림: 38 */ 반올림의 경우 내림 함수인 floor()에서 +0..

    [Algorithm] 공간 / 시간 복잡도 분석

    복잡도는 크게 공간 복잡도와 시간 복잡도로 나뉜다. 복잡도를 분석하는 것은 한 문제에 대해서 해결방법으로 나올수 있는 알고리즘이 여러개가 있기 때문이다. 그 다수의 알고리즘의 성능을 비교해야 할 필요가 있으므로 공간 / 시간 복잡도를 분석하여 표기한다. 이때 표기 방법에는 주로 점근적 표기법 (Asymptotic Notation)이 쓰인다. 시간 복잡도(Time Complexity) -시간복잡도: 프로그램의 수행시간을 분석하는 것, 반복문에 크게 영향을 받음 -계산 방법 1) 연산 횟수의 함수가 주어진 경우 최고차항의 계수와 그보다 낮은 차수의 항을 제외시키면 된다. 예를 들어 7n^5+5n^3+3n^2+3 라는 식이 주어졌을때 최고차항인 7n^5 의 계수인 7과 나머지 5n^3+3n^2+3 를 제외 시..