목록Problem Solving (223)
Life Engineering
https://www.acmicpc.net/problem/1197 1197번: 최소 스패닝 트리 첫째 줄에 정점의 개수 V(1 ≤ V ≤ 10,000)와 간선의 개수 E(1 ≤ E ≤ 100,000)가 주어진다. 다음 E개의 줄에는 각 간선에 대한 정보를 나타내는 세 정수 A, B, C가 주어진다. 이는 A번 정점과 B번 정점이 www.acmicpc.net import heapq q=[] V, E=map(int, input().split()) parents=[0] cnt=0 ans=0 def find(a): if parents[a]==a: return a parents[a]=find(parents[a]) return parents[a] def union(a, b): pa=find(a) pb=find(b)..
https://www.acmicpc.net/problem/17471 17471번: 게리맨더링 선거구를 [1, 4], [2, 3, 5, 6]으로 나누면 각 선거구의 인구는 9, 8이 된다. 인구 차이는 1이고, 이 값보다 더 작은 값으로 선거구를 나눌 수는 없다. www.acmicpc.net #include #include #include #include #include using namespace std; int N; int populations[11]; vector adj(11); int ans = INT_MAX; bool visit[11]; vector A; vector B; int calc(vector& v){ int sum=0; for (int i=0; i x; adj[i].push_back(x)..
https://www.acmicpc.net/problem/16637 16637번: 괄호 추가하기 첫째 줄에 수식의 길이 N(1 ≤ N ≤ 19)가 주어진다. 둘째 줄에는 수식이 주어진다. 수식에 포함된 정수는 모두 0보다 크거나 같고, 9보다 작거나 같다. 문자열은 정수로 시작하고, 연산자와 정수가 www.acmicpc.net #include #include #include #include #include #include using namespace std; int N; string s; vector operands; vector operators; bool visit[19]; long long ans = (long long) -1 * pow(2, 31); long long calc() { long lo..
https://www.acmicpc.net/problem/16235 16235번: 나무 재테크 부동산 투자로 억대의 돈을 번 상도는 최근 N×N 크기의 땅을 구매했다. 상도는 손쉬운 땅 관리를 위해 땅을 1×1 크기의 칸으로 나누어 놓았다. 각각의 칸은 (r, c)로 나타내며, r은 가장 위에서부터 www.acmicpc.net #include #include #include using namespace std; struct Trees { vector list; }; int N, M, K; int A[11][11]; int food[11][11]; struct Trees graph[11][11]; int dx[8] = { -1,-1,-1,0,0,1,1,1 }; int dy[8] = { -1,0,1,-1,1..