본문 바로가기

전체 글105

[BOJ] 백준 1016번: 제곱ㄴㄴ수 제곱으로 나누어떨어지지 않는 수를 찾기 위하여 1부터 _max의 제곱근 까지의 소수를 찾아 리스트에 저장한 후 _min과 _max의 범위가 최대 100만 차이임을 이용하여 찾은 소수 제곱에 대한 배수를 채로 걸러 전체 수에서 뺌 #include #include #include #include #include #include using namespace std; typedef pair pii; typedef long long ll; ll _min, _max; bool s[1000001] = { 0, }; bool ans[1000001] = { 0 , }; vector v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL.. 2020. 6. 19.
[BOJ] 백준 16491번: 대피소 찾기 CCW를 이용한 선분 교차 판별 알고리즘을 통해 DFS 탐색하는 문제 #include #include #include #include #include using namespace std; typedef pair pii; int n; int rsy[101] = { 0, }; // 같은 y좌표를 갖는 로봇 int dsy[101] = { 0, }; // 같은 y 좌표를 갖는 대피소 pii pr[101]; pii pd[101]; int tmp[101]; bool visit[101]; int ccw(int x1, int y1, int x2, int y2, int x3, int y3) { int left = x1 * y2 + x2 * y3 + x3 * y1; int right = x1 * y3 + x3 * y2 +.. 2020. 6. 19.
[BOJ] 백준 1086번: 박성원 주어진 수 K로 1~100 까지 수를 나눈 나머지를 dp배열에 저장하여 메모이제이션 탐색 종만북에 비슷한 문제가 있음 #include #include #include #include #include #include using namespace std; typedef long long ll; ll n,k; ll mod[16][101]; ll dp[100000][100]; // state에서 나머지 k인 경우 string arr[16]; ll ans =0; ll gcd(ll a,ll b){ ll c= a %b; while(c){ a= b; b= c; c = a%b; } return b; } ll recv(ll state, ll m){ if(state == (1 k ; // j arr[i] mod k = mo.. 2020. 6. 17.
[BOJ] 백준 1017번: 소수쌍 소수 = 홀수 + 짝수의 조합으로만 가능한 아이디어를 시작으로 홀수와 짝수를 두 개의 그룹으로 나눠, 시작하는 수의 짝을 고정하여 이분매칭을 반복하는 문제 #include #include #include #include using namespace std; typedef long long ll; bool s[2001] = { 0, }; int arr[1001]; int ma[1001]; int curd; bool visit[1001]; int _lsize, _rsize; vector l, r; bool dfs(int node) { if (visit[node]) return false; visit[node] = true; for (int i = 0; i < _rsize; i++) { if (i != cur.. 2020. 6. 17.