TIL day 49

2025. 2. 27. 12:15·TIL

1. 코딩테스트


어제 공부한 집합 관련 문제를 추가적으로 풀어보았습니다.

https://www.acmicpc.net/problem/1717

  • 이 문제는 어제 유니온-파인드 구현해보는 문제와 거의 유사해서 어려움 없이 풀었습니다.
  • 주의할 점은 집합이 0 ~ n 까지이기 때문에 처음에 값을 초기화하는 부분에서 <= n을 해주어야 하는 점입니다. (< n으로 해서 틀림)
더보기
#include <iostream>
using namespace std;

int m, n;
int Parent[1'000'002];
int Rank[1'000'002];

//부모 찾기
int Find(int a)
{
	if (Parent[a] == a)
		return a;
	Parent[a] = Find(Parent[a]);

	return Parent[a];
}

void Union(int a, int b)
{
	int rootA = Find(a);
	int rootB = Find(b);

	if (rootA != rootB)
	{
		//B랭크가 더 크면
		if (Rank[rootA] < Rank[rootB])
		{
			//B쪽으로 붙이기
			Parent[rootA] = rootB;
		}
		else if (Rank[rootA] > Rank[rootB])
		{
			Parent[rootB] = rootA;
		}
		else
		{
			Parent[rootA] = rootB;
			Rank[rootB]++;
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	cin >> n >> m;
	
	for (int i = 0; i <= n; ++i)
	{
		Parent[i] = i;
		Rank[i] = 0;
	}
	while (m--)
	{
		int k, a, b;

		cin >> k >> a >> b;

		if(k == 1)
		{ 
			if (Find(a) == Find(b))
				cout << "YES\n";
			else
				cout << "NO\n";
		}
		else
		{
			Union(a, b);			
		}
	}
}

https://www.acmicpc.net/problem/7511

  • 이 문제도 그냥 똑같습니다.
  • 주의점은 ios::sync_with_stdio(0); 와 cin.tie(0);를 안쓰면 통과를 못한다는 점입니다.
더보기
#include <iostream>
#include <vector>

using namespace std;

int Parent[1'000'002];
int Rank[1'000'002];

int Find(int a)
{
	if (Parent[a] == a)
		return a;
	Parent[a] = Find(Parent[a]);

	return Parent[a];
}

void Union(int a, int b)
{
	int rootA = Find(a);
	int rootB = Find(b);

	if (rootA != rootB)
	{
		//B랭크가 더 크면
		if (Rank[rootA] < Rank[rootB])
		{
			//B쪽으로 붙이기
			Parent[rootA] = rootB;
		}
		else if (Rank[rootA] > Rank[rootB])
		{
			Parent[rootB] = rootA;
		}
		else
		{
			Parent[rootA] = rootB;
			Rank[rootB]++;
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T;
	cin >> T;
	for(int j = 1; j <= T; ++j)
	{
		int n, k;
		cin >> n; //user
		cin >> k; //friend

		for (int i = 0; i <= n; ++i)
		{
			Parent[i] = i;
			Rank[i] = 0;
		}

		while (k--)
		{
			int a, b;
			cin >> a >> b;

			Union(a, b); //와 b는 친구
		}
		int m;
		cin >> m;
		cout << "Scenario " << j << ":\n";

		//m개의 정답 출력
		while (m--)
		{
			int u, v;
			cin >> u >> v;
			
			if (Find(u) == Find(v))
				cout << 1 << "\n";
			else
				cout << 0 << "\n";						
		}
		cout << "\n";
	}
}

 

 

2. 언리얼


어제 해결하지 못한 총기 스폰에 관련된 이슈를 해결하였습니다.

https://gbleem.tistory.com/104

 

UE5 Issues : 총기 스폰 및 포인터

이번 글의 주제는 인벤토리에 가지고 있는 총기와 현재 장착하고 있는 총기를 연동하는 방식에 대한 내용이다. 1. 전체적인 로직UI의 동작왼쪽은 무기를 획득하기 전에 모습이다. 이때는 UI의 버

gbleem.tistory.com

 

또한 추가적으로 총기의 반동과 데칼 탄피효과 등을 추가하였습니다.

https://gbleem.tistory.com/105

 

Unreal Engine - 총기 반동, 데칼, 탄피 효과

1. 총기 반동 구현가장 쉬운 방법은 PlayerController의 AddPitchInput과 AddYawInput을 사용하는 방식이다.CalculateRecoilValue 함수는 Current Weapon이 가진 변수를 가져와서 캐릭터 변수에 저장하는 동작을 하는

gbleem.tistory.com

 

'TIL' 카테고리의 다른 글

TIL day 51  (0) 2025.03.05
TIL day 50  (0) 2025.02.28
TIL day 48  (0) 2025.02.26
TIL day 47  (0) 2025.02.26
TIL day 46  (0) 2025.02.24
'TIL' 카테고리의 다른 글
  • TIL day 51
  • TIL day 50
  • TIL day 48
  • TIL day 47
gbleem
gbleem
gbleem 님의 블로그 입니다.
  • gbleem
    gbleem 님의 블로그
    gbleem
  • 전체
    오늘
    어제
    • 분류 전체보기 (184)
      • Unreal Engine (73)
      • C++ (19)
      • 알고리즘(코딩테스트) (27)
      • TIL (60)
      • CS (4)
      • 툴 (1)
  • 블로그 메뉴

    • 홈
    • 카테고리
  • 링크

    • 과제용 깃허브
    • 깃허브
    • velog
  • 공지사항

  • 인기 글

  • 태그

    additive animation
    enhanced input system
    Vector
    actor 클래스
    C++
    addonscreendebugmessage
    BFS
    character animation
    템플릿
    매크로 지정자
    싱글턴
    applydamage
    blend pose
    map을 vector로 복사
    gamestate
    const
    motion matching
    상속
    cin함수
    DP
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
gbleem
TIL day 49
상단으로

티스토리툴바