-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 17-yuyu0830
- Loading branch information
Showing
11 changed files
with
488 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
//#include <iostream> | ||
//#include <queue> | ||
//#include <vector> | ||
// | ||
//using namespace std; | ||
// | ||
//int N, M, K, X, a, b, minDist; | ||
//deque<deque<int>> town; | ||
//queue<int> q; | ||
//vector<int> dist; | ||
//vector<int> answer; | ||
// | ||
//void Solve() | ||
//{ | ||
// cin >> N >> M >> K >> X; | ||
// N++; | ||
// town.assign(N, deque<int>()); | ||
// dist.assign(N, -1); | ||
// | ||
// for (int i = 0; i < M; i++) | ||
// { | ||
// cin >> a >> b; | ||
// | ||
// town[a].push_back(b); | ||
// } | ||
// | ||
// minDist = -1; | ||
// q.push(X); | ||
// dist[X] = 0; | ||
// | ||
// while (!q.empty()) | ||
// { | ||
// int cur = q.front(); | ||
// q.pop(); | ||
// | ||
// for (const int& val : town[cur]) | ||
// { | ||
// if (dist[val] != -1) continue; | ||
// q.push(val); | ||
// dist[val] = dist[cur] + 1; | ||
// minDist = max(minDist, dist[val]); | ||
// } | ||
// } | ||
// | ||
// for (int i = 0; i < dist.size(); i++) | ||
// { | ||
// if (dist[i] == K) answer.push_back(i); | ||
// } | ||
// | ||
// if (answer.size()) | ||
// { | ||
// for (const int& val : answer) | ||
// { | ||
// cout << val << "\n"; | ||
// } | ||
// } | ||
// else cout << -1; | ||
//} | ||
// | ||
//int main() | ||
//{ | ||
// cin.tie(nullptr); | ||
// ios::sync_with_stdio(false); | ||
// | ||
// Solve(); | ||
// | ||
// return 0; | ||
//} | ||
|
||
#include <iostream> | ||
#include <queue> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
int N, M, K, X, A, B; | ||
int cur, dist; | ||
queue<pair<int, int>> q; | ||
vector<vector<int>> towns; | ||
vector<bool> visited; | ||
priority_queue<int, vector<int>, greater<int>> answer; | ||
|
||
void Solve() | ||
{ | ||
cin >> N >> M >> K >> X; | ||
|
||
N++; | ||
towns.assign(N, vector<int>()); | ||
visited.assign(N, false); | ||
|
||
while (M--) | ||
{ | ||
cin >> A >> B; | ||
towns[A].push_back(B); | ||
} | ||
|
||
q.push({ X, 0 }); | ||
visited[X] = true; | ||
|
||
while (!q.empty()) | ||
{ | ||
cur = q.front().first; | ||
dist = q.front().second; | ||
|
||
q.pop(); | ||
|
||
if (dist == K) | ||
{ | ||
answer.push(cur); | ||
continue; | ||
} | ||
|
||
for (auto v : towns[cur]) | ||
{ | ||
if (visited[v]) continue; | ||
q.push({ v, dist + 1 }); | ||
visited[v] = true; | ||
} | ||
} | ||
|
||
if (answer.empty()) | ||
{ | ||
cout << -1; | ||
return; | ||
} | ||
|
||
while (!answer.empty()) | ||
{ | ||
cout << answer.top() << "\n"; | ||
answer.pop(); | ||
} | ||
return; | ||
} | ||
|
||
int main() | ||
{ | ||
cin.tie(nullptr); | ||
ios::sync_with_stdio(false); | ||
|
||
Solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
InSange/๊ทธ๋ํ/2285_Maximum_Total_Importance_of_Roads.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <vector> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
long long maximumImportance(int n, vector<vector<int>>& roads) { | ||
vector<vector<int>> conn; // road | ||
priority_queue<pair<long long, int>> pq; // connect degree first: degree, second: index | ||
long long answer = 0; | ||
|
||
conn.assign(n, vector<int>()); | ||
|
||
for (auto road : roads) | ||
{ | ||
int v1 = road[0]; | ||
int v2 = road[1]; | ||
|
||
conn[v1].push_back(v2); | ||
conn[v2].push_back(v1); | ||
} | ||
|
||
for (int i = 0; i < n; i++) | ||
{ | ||
pq.push({ conn[i].size(), i }); | ||
} | ||
|
||
while (!pq.empty()) | ||
{ | ||
pair<long long, int> cur; | ||
cur = pq.top(); | ||
pq.pop(); | ||
|
||
answer += (n-- * cur.first); | ||
} | ||
|
||
return answer; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <vector> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
string convert(string s, int numRows) { | ||
if (numRows <= 1 || s.size() <= numRows) return s; | ||
|
||
vector<string>v(numRows, ""); | ||
|
||
int i, j, dir; | ||
j = 0; | ||
dir = -1; | ||
|
||
for (i = 0; i < s.size(); i++) | ||
{ | ||
if (j == numRows - 1 || j == 0) dir *= -1; | ||
v[j] += s[i]; | ||
if (dir == 1) j++; | ||
else j--; | ||
} | ||
|
||
string answer; | ||
answer = ""; | ||
|
||
for (auto c : v) | ||
{ | ||
answer += c; | ||
} | ||
|
||
return answer; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
int T, N, num, answer; | ||
priority_queue < int> pq; | ||
deque<int> logs; | ||
|
||
void Solve() | ||
{ | ||
cin >> T; | ||
|
||
while (T--) | ||
{ | ||
answer = 0; | ||
cin >> N; | ||
|
||
for (int i = 0; i < N; i++) | ||
{ | ||
cin >> num; | ||
pq.push(num); | ||
} | ||
|
||
bool isLeft = true; | ||
|
||
while (!pq.empty()) | ||
{ | ||
if (isLeft) | ||
logs.push_front(pq.top()); | ||
else //if(!isLeft) | ||
logs.push_back(pq.top()); | ||
|
||
pq.pop(); | ||
isLeft = (isLeft ? false : true); | ||
} | ||
|
||
int lsize = logs.size(); | ||
|
||
for (int i = 0; i < lsize; i++) | ||
{ | ||
int next = (i + 1) % lsize; | ||
answer = max(answer, abs(logs[i] - logs[next])); | ||
} | ||
|
||
cout << answer << "\n";; | ||
logs.clear(); | ||
} | ||
|
||
} | ||
|
||
int main() | ||
{ | ||
ios::sync_with_stdio(false); | ||
cin.tie(nullptr); | ||
|
||
Solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int N, K, l, r, lastDrink; | ||
vector<int> wine; | ||
bool isLeft = false; | ||
long long answer = 0; | ||
|
||
void Solve() | ||
{ | ||
cin >> N >> K; | ||
|
||
wine.assign(N, 0); | ||
|
||
for (int i = 0; i < N; i++) | ||
{ | ||
cin >> wine[i]; | ||
} | ||
|
||
sort(wine.begin(), wine.end()); | ||
|
||
l = 0; | ||
r = N - 1; | ||
answer = 0; | ||
lastDrink = 0; | ||
|
||
while (K--) | ||
{ | ||
if (isLeft == true) // ยธร ยพรธยดร ยฐร | ||
{ | ||
lastDrink = wine[l]; | ||
l++; | ||
} | ||
else// if(isLeft == false) // ยธร รรยดร ยฐร | ||
{ | ||
answer += wine[r] - lastDrink; | ||
r--; | ||
} | ||
|
||
isLeft = (isLeft + 1) & 1; | ||
} | ||
|
||
cout << answer; | ||
} | ||
|
||
int main() | ||
{ | ||
ios::sync_with_stdio(false); | ||
cin.tie(nullptr); | ||
|
||
Solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
n = int(input()) | ||
m = list(map(int,input().split())) | ||
|
||
for i in range(1,n): | ||
m[i] = max(m[i], m[i]+m[i-1]) | ||
print(max(m)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.