TIL
TIL day 75
gbleem
2025. 4. 7. 12:33
1. 코딩테스트
class 4 한 문제와 class 5 한 문제를 풀었습니다.
DP 문제로 유명한 LCS문제
https://www.acmicpc.net/problem/9251
더보기
#include <iostream>
#include <string>
using namespace std;
string str1, str2;
int dp[1002][1002];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> str1 >> str2;
for (int i = 1; i <= str1.size(); ++i)
{
for (int j = 1; j <= str2.size(); ++j)
{
if (str1[i - 1] == str2[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
cout << dp[str1.size()][str2.size()];
}
class 5 다각형의 면적
https://www.acmicpc.net/problem/2166
- 우선 외적을 통해서 원점과 다각형의 두 개의 점을 연결한 삼각형의 넓이를 구했습니다.
- 주의할 점은 오목한 다각형이 존재하기 때문에, 넓이를 더할 때 절댓값을 취하지 않고
- 결과를 낼 때, 절댓값을 취해서 양수값으로 만들어주면 된다.
더보기
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
pair<double, double> board[10'002];
int n;
double answer = 0;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> board[i].first >> board[i].second;
}
for (int i = 0; i < n; ++i)
{
int j = (i + 1) % n;
answer += (board[i].first * board[j].second) - (board[i].second * board[j].first);
}
answer = abs(answer);
answer /= 2;
cout << fixed;
cout.precision(1);
cout << answer;
}
2. 언리얼
멀티플레이 로비 시스템 제작중...