728x90
반응형

코딩테스트 250

백준, BOJ, 1992번 C++ [CPP]

이것 또한 분할 정복 Z자로 진행하는 방식이다. 더 어려워진다면 Z자가 아니라 새롭게 진행하는 방식이겠지 시간도 많다 https://www.acmicpc.net/problem/1992 #맞은 풀이 틀린 부분에 대해서는 내가 주석을 좀 달아놨다. #include #include #include #define X first #define Y second using namespace std; int N; int pic[65][65]; //N의 크기를 가지고 왼쪽 위 좌표가 a,b인 정사각형 void func(int N, int a, int b) { //가장 잘게 쪼갰을 때 if (N == 1) { //구현 //해당 값 출력 cout

백준, BOJ, 2630번 C++ [CPP]

이런 문제는 쉽게 짜면 쉽게 풀리지만 순서를 허투루 적었다간 나처럼 30분 날린다. https://www.acmicpc.net/problem/2630 나의 첫번째풀이... (틀림) -> 전체를 검사하지 않음. (즉, 전체는 틀렸다고 가정하고 품) #include #include #define X first #define Y second using namespace std; int N; int sample[129][129]; int white = 0; int blue = 0; //N사각형 크기, a,b해당 사각형의 왼쪽 위 좌표 void func(int N, int a, int b) { if (N == 1) { if (sample[a][b] == 1) { blue++; } else { white++; } ..

STL 우선순위 큐, Priority Queue 사용법 [C++]

유용한 STL인 큐 중에서 우선순위 큐를 알아보자 그냥 큐와 무엇이 다른지도 알아보자 Priority queues are a type of container adaptors, specifically designed such that its first element is always the greatest of the elements it contains, according to some strict weak ordering criterion. 일반적으로 첫번째 원소가 제일 큰 값을 가지게 하는 컨테이너다. **물론 첫번째 원소가 제일 작은 값을 나오게 할 수도 있다. This context is similar to a heap, where elements can be inserted at any mome..

array와 container들을 초기화시키는 여러가지 방법

1. fill 함수 - 헤더에 포함 특정한 값으로 채우고 싶을 때나 그냥 초기화할 때 fill(시작주소, 끝주소, 넣고싶은 값) 이라고 생각하면 좋다. void 라 반환값은 없다. #include // std::fill #include // std::vector int main () { std::vector myvector (8); // myvector: 0 0 0 0 0 0 0 0 std::fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0 std::fill (myvector.begin()+3,myvector.end()-2,8); // myvector: 5 5 5 8 8 8 0 0 return 0; } 만약 배열이라면 f..

Container 원소들 역순정렬하기

어떤 컨테이너에 원소들이 들어있고 역순으로 정렬되기를 원한다면 을 include해야 쓸 수 있다. https://www.cplusplus.com/reference/algorithm/reverse/ reverse()를 쓰면 된다. #include #include using namespace std; int main(){ vector a; reverse(a.begin(), a.end()); return 0; } https://www.cplusplus.com/reference/iterator/BidirectionalIterator/ 다만 눈에 띄는 점이라면 void reverse (BidirectionalIterator first, BidirectionalIterator last); 즉, 그냥 이터레이터가 아..

백준, BOJ, 1676번 C++ [CPP]

10^승의 개수가 0의 개수란 것을 안다면 쉽다. 다만 숫자가 크기에..잘해봐야한다. 더군다나 시간제한도 있다 https://www.acmicpc.net/problem/1676 #맞는 풀이 #include using namespace std; //0의 개수는 소인수분해 시 2와 5의 개수에 따라 결정된다. //즉, 모든 숫자에 대해서 2,5의 개수파악, 근데 2의 개수가 압도적으로 많으므로 5의 개수만 파악하면 알아서 되겠다. int dp[501]; int main(){ int N; cin >> N; for(int i = 1; i

백준, BOJ, 1037번 C++ [CPP]

이문제는 내가 개똥같이 풀었다.. 하지만 감은 어느정도 왔었다. https://www.acmicpc.net/problem/1037 시간도 넉넉하다. 메모리도 넉넉하다. long long을 쓸 것 같다는 생각을 하자. #맞는 풀이 #include #include #define M 1000000 using namespace std; //약수 개수 int func(int a){ int cnt = 0; for(int i =2; i> num; for(int i =0; i> a; vec.push_back(a); } int ans = 0; for(int i = 2; i

728x90
반응형