요즘 sqld 시험 준비로 정신이 없다. 코드 공부 잊지말기!
브루트 포스(brute force) = 완전 탐색 알고리즘
모든 경우의 수를 탐색하면서 조건에 충족되는 결과를 가져옴
pair<type, type>
- 저장한 값은 .first, .second 이렇게 접근 가능
- 2개의 정렬 조건으로 정렬하고 싶을때 사용하면 좋음
<pair 예시>
#include <iostream>
#include <algorithm> // abs() 포함되어있음
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
pair<int, double> test_p;
int main(void){
//1. pair 객체 test_p 생성 후 값 대입
test_p.first=1;
test_p.second = 0.5;
//1-1
test_p = make_pair(2, 3.1);
cout << test_p.first <<endl;
cout << test_p.second<<endl;
//2. 다른 방법
typedef pair<int,int> intp;
vector<intp> arr;
// 3. 다른 방법 (2와 동일)
vector<pair<int,int>> arr1;
}
[C++ STL]pair 클래스 사용방법
안녕하세요. 오늘은 알아두면 유용한 C++의 Pair 클래스를 소개해겠습니다. 1. pair 클래스 Pair 클래스는 사용자가 지정한 2개의 타입의 데이터를 저장하는데 사용합니다. 서로 연관된 2개의 데이터
ya-ya.tistory.com
백준 7568번 - Silver V
// 덩치 등수
#include <iostream>
#include <algorithm> // abs() 포함되어있음
#include <vector>
#include <cmath>
using namespace std;
pair<int, int> p[50];
int main(void){
int n, rank=1;
cin>>n;
for(int i=0;i<n;i++){
cin>>p[i].first>>p[i].second;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i].first<p[j].first&&p[i].second<p[j].second)
rank++;
}
cout << rank<<" ";
rank=1;
}
}
'코딩 > C++' 카테고리의 다른 글
C++ 알고리즘 연습문제 - 함수사용 (0) | 2022.03.22 |
---|---|
C++ - 배열 요소 (calloc 사용) (0) | 2022.03.20 |
백준 문제풀이 C++ [220226] - 정렬 (0) | 2022.02.26 |
백준 문제풀이 C++ [220226] - 브루트 포스 (0) | 2022.02.26 |
백준 문제풀이 C++ [220225] - 기본 수학 1단계 (0) | 2022.02.25 |