Skip to content

Commit 3c17cc6

Browse files
committed
merge
2 parents caebe40 + e3e37b7 commit 3c17cc6

File tree

16 files changed

+550
-0
lines changed

16 files changed

+550
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int n, m, ret;
6+
int arr[1001][1001], dp[1001][1001];
7+
8+
int main() {
9+
ios::sync_with_stdio(false);
10+
cin.tie(NULL); cout.tie(NULL);
11+
12+
cin >> m >> n;
13+
14+
for (int i = 1; i <= m; i++) {
15+
for (int j= 1; j <= n; j++) {
16+
cin >> arr[i][j];
17+
}
18+
}
19+
20+
for (int i = 1; i <= m; i++) {
21+
for (int j = 1; j <= n; j++) {
22+
if (!arr[i][j]) {
23+
if (!dp[i - 1][j - 1] || !dp[i][j - 1] || !dp[i - 1][j]) {
24+
dp[i][j] = 1;
25+
}
26+
else {
27+
dp[i][j] = min(min(dp[i - 1][j - 1], dp[i][j - 1]), dp[i - 1][j]) + 1;
28+
}
29+
ret = max(ret, dp[i][j]);
30+
}
31+
}
32+
}
33+
34+
cout << ret << '\n';
35+
36+
return 0;
37+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package week04.BOJ_4386_별자리만들기;
2+
3+
import java.util.*;
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
class BOJ4386 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
int N = Integer.parseInt(br.readLine());
11+
double[][] stars = new double[N][2];
12+
for (int i = 0; i < N; i++) {
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
stars[i][0] = Double.parseDouble(st.nextToken());
15+
stars[i][1] = Double.parseDouble(st.nextToken());
16+
}
17+
18+
ArrayList<Edge>[] edges = new ArrayList[N];
19+
for (int i = 0; i < N; i++) {
20+
edges[i] = new ArrayList<>();
21+
}
22+
23+
//모든 거리 저장
24+
for (int i = 0; i < N-1; i++) {
25+
for (int j = i+1; j < N; j++) {
26+
double dist = getDistance(stars[i][0], stars[i][1], stars[j][0], stars[j][1]);
27+
edges[i].add(new Edge(j, dist));
28+
edges[j].add(new Edge(i, dist));
29+
}
30+
}
31+
32+
PriorityQueue<Edge> pq = new PriorityQueue<>();
33+
boolean[] visit = new boolean[N];
34+
pq.add(new Edge(0, 0.0));
35+
36+
double total = 0.0;
37+
while (!pq.isEmpty()) {
38+
Edge poll = pq.poll();
39+
if (visit[poll.num]) continue;
40+
visit[poll.num] = true;
41+
total += poll.dist;
42+
43+
for (Edge next : edges[poll.num]) {
44+
if (!visit[next.num]) {
45+
pq.add(next);
46+
}
47+
}
48+
}
49+
50+
System.out.printf("%.2f", total);
51+
}
52+
53+
static double getDistance(double x1, double y1, double x2, double y2) {
54+
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
55+
}
56+
57+
}
58+
59+
class Edge implements Comparable<Edge> {
60+
int num;
61+
double dist;
62+
63+
Edge(int num, double dist) {
64+
this.num = num;
65+
this.dist = dist;
66+
}
67+
68+
@Override
69+
public int compareTo(Edge o) {
70+
return Double.compare(this.dist, o.dist);
71+
}
72+
}
73+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package study.week04;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.PriorityQueue;
7+
8+
// 별자리 만들기
9+
public class BOJ_4386 {
10+
11+
static class Point{
12+
int num;
13+
double x;
14+
double y;
15+
16+
public Point(int num, double x,double y){
17+
this.num = num;
18+
this.x = x;
19+
this.y = y;
20+
}
21+
}
22+
23+
static class Edge{
24+
int start;
25+
int end;
26+
double weight;
27+
28+
public Edge(int start, int end, double weight){
29+
this.start = start;
30+
this.end = end;
31+
this.weight = weight;
32+
}
33+
}
34+
35+
static int[] parent;
36+
static PriorityQueue<Edge> pq;
37+
38+
public static void main(String[] args) throws IOException {
39+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
40+
41+
int N = Integer.parseInt(br.readLine());
42+
Point [] points = new Point[N];
43+
44+
for(int i=0; i<N; i++){
45+
String [] s = br.readLine().split(" ");
46+
double x = Float.parseFloat(s[0]);
47+
double y = Float.parseFloat(s[1]);
48+
49+
points[i] = new Point(i, x,y);
50+
}
51+
52+
pq = new PriorityQueue<>((e1, e2) -> {
53+
if(e1.weight < e2.weight) return -1;
54+
return 1;
55+
});
56+
57+
for (int i=0; i<N; i++){
58+
for (int j = i+1; j<N; j++){
59+
double weight = distance(points[i], points[j]);
60+
pq.add(new Edge(points[i].num, points[j].num, weight));
61+
}
62+
}
63+
64+
parent = new int[N];
65+
for(int i=0; i<N; i++){
66+
parent[i] = i;
67+
}
68+
69+
double ans = 0;
70+
71+
while(!pq.isEmpty()){
72+
Edge edge = pq.poll();
73+
int start = edge.start;
74+
int end = edge.end;
75+
double cost = edge.weight;
76+
77+
if(find(start) != find(end)){
78+
ans += cost;
79+
union(start, end);
80+
}
81+
}
82+
83+
System.out.println(ans);
84+
85+
}
86+
87+
public static void union(int x, int y){
88+
int rootA = find(x);
89+
int rootB = find(y);
90+
parent[Math.min(rootA, rootB)] = Math.max(rootA, rootB);
91+
}
92+
93+
private static int find(int x) {
94+
if(x != parent[x]){
95+
parent[x] = find(parent[x]);
96+
}
97+
98+
return parent[x];
99+
}
100+
101+
private static double distance(Point p1, Point p2) {
102+
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
103+
}
104+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 이번 주도 파이팅!🔥
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int t, n, ret;
8+
int main() {
9+
ios::sync_with_stdio(false);
10+
cin.tie(NULL); cout.tie(NULL);
11+
12+
cin >> t;
13+
while (t--) {
14+
cin >> n;
15+
vector<pair<int, int>> scores;
16+
ret = 1;
17+
for (int i = 0; i < n; i++) {
18+
int a, b;
19+
cin >> a >> b;
20+
scores.push_back({a, b});
21+
}
22+
sort(scores.begin(), scores.end());
23+
24+
int _max = scores[0].second;
25+
for (int i = 1; i < n; i++) {
26+
if (scores[i].second <= _max) {
27+
_max = scores[i].second;
28+
ret++;
29+
}
30+
}
31+
cout << ret << '\n';
32+
}
33+
return 0;
34+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package study.week05;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.Arrays;
7+
import java.util.Stack;
8+
9+
// 가장 긴 증가하는 부분 수열4
10+
public class BOJ_14002 {
11+
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
StringBuilder sb = new StringBuilder();
15+
16+
int N = Integer.parseInt(br.readLine());
17+
18+
int [] arr = new int[N];
19+
String []s = br.readLine().split(" ");
20+
21+
for(int i=0; i<N; i++){
22+
arr[i] = Integer.parseInt(s[i]);
23+
}
24+
25+
int [] dp = new int[N];
26+
int [] pre = new int[N];
27+
Arrays.fill(dp, 1);
28+
pre[0] = 0;
29+
30+
for(int i=1; i<N; i++){
31+
for(int j=0; j < i; j++){
32+
if(arr[i] > arr[j]){
33+
if(dp[i] < dp[j] + 1){
34+
dp[i] = dp[j] + 1;
35+
pre[i] = j;
36+
}
37+
}else{
38+
if(dp[i] <= 1) {
39+
dp[i] = 1;
40+
pre[i] = i;
41+
}
42+
}
43+
}
44+
}
45+
46+
int max = 0;
47+
int maxIdx = 0;
48+
for(int i=0; i<N; i++){
49+
if(max < dp[i]){
50+
max = dp[i];
51+
maxIdx = i;
52+
}
53+
}
54+
55+
// 최대 부분수열 길이
56+
sb.append(max).append("\n");
57+
58+
Stack<Integer> st = new Stack<>();
59+
st.push(arr[maxIdx]);
60+
int tmp = maxIdx;
61+
62+
while(true){
63+
if(tmp == pre[tmp])break;
64+
tmp = pre[tmp];
65+
st.push(arr[tmp]);
66+
}
67+
68+
while(!st.isEmpty()){
69+
sb.append(st.pop()).append(" ");
70+
}
71+
72+
System.out.println(sb);
73+
}
74+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 이번 주도 파이팅!🔥
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
#include <queue>
3+
#include <vector>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
priority_queue<int, vector<int>, greater<int>> pq;
8+
vector<pair<int, int>> v;
9+
int n, p, d, ret;
10+
int main() {
11+
ios_base::sync_with_stdio(false);
12+
cin.tie(NULL); cout.tie(NULL);
13+
14+
cin >> n;
15+
for (int i = 0; i < n; i++) {
16+
cin >> d >> p;
17+
v.push_back({d, p});
18+
}
19+
sort(v.begin(), v.end());
20+
for (int i = 0; i < n; i++) {
21+
pq.push(v[i].second);
22+
if (v[i].first < pq.size()) {
23+
pq.pop();
24+
}
25+
}
26+
27+
while (pq.size()) {
28+
ret += pq.top();
29+
pq.pop();
30+
}
31+
32+
cout << ret << '\n';
33+
34+
return 0;
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# 이번 주도 파이팅!🔥

0 commit comments

Comments
 (0)