-
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' of https://github.com/AlgoLeadMe/AlgoLeadMe-8
# Conflicts: # InSange/README.md
- Loading branch information
Showing
5 changed files
with
156 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
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,21 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int dp[1000001]; | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int num; | ||
cin >> num; | ||
dp[1] = 0; | ||
dp[2] = 1; | ||
dp[3] = 1; | ||
for (int i = 4; i <= num; i++) { | ||
dp[i] = dp[i - 1] + 1; | ||
if (i % 3 == 0) | ||
dp[i] = min(dp[i], dp[i / 3] + 1); | ||
if (i % 2 == 0) | ||
dp[i] = min(dp[i], dp[i / 2] + 1); | ||
} | ||
cout << dp[num]; | ||
|
||
} |
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,34 @@ | ||
#include<iostream> | ||
#include<set> | ||
using namespace std; | ||
int parent[1001]; | ||
set<int>s; | ||
int find_parent(int a) { | ||
if (parent[a] == a) return a; | ||
else return parent[a]=find_parent(parent[a]); | ||
} | ||
void unionn(int a, int b) { | ||
int root_a = find_parent(a); | ||
int root_b = find_parent(b); | ||
if (a == b) return; | ||
if (root_a < root_b) parent[root_b] = root_a; | ||
else parent[root_a] = root_b; | ||
} | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int v, e,v1,v2; | ||
cin >> v >> e; | ||
for (int j = 1; j <= v; j++) { | ||
parent[j] = j; | ||
} | ||
for (int i = 0; i < e; i++) { | ||
cin >> v1 >> v2; | ||
unionn(v1, v2); | ||
} | ||
for (int i = 1; i <= v; i++) { | ||
int v3=find_parent(i); | ||
s.insert(v3); | ||
} | ||
cout << s.size(); | ||
} |
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,21 @@ | ||
from itertools import combinations | ||
|
||
L,C = map(int,input().split()) | ||
|
||
k = list(map(str,input().split())) | ||
vowels = 'aeiou' | ||
|
||
vowel_cnt = 0 | ||
consonant_cnt = 0 | ||
|
||
result = [] | ||
for c in combinations(k,L): | ||
vowel_str = ''.join(sorted(c)) | ||
vowel_cnt = sum(1 for char in vowel_str if char in vowels) | ||
consonant_cnt = L - vowel_cnt | ||
if vowel_cnt >=1 and consonant_cnt >=2: | ||
result.append(vowel_str) | ||
|
||
result.sort() | ||
for word in result: | ||
print(word) |
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,72 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
typedef pair<int, int> ii; | ||
|
||
struct cmp{ | ||
bool operator() (ii &a, ii &b) { | ||
if (a.first > b.first) return true; | ||
return false; | ||
} | ||
}; | ||
|
||
struct cmpB{ | ||
bool operator() (ii &a, ii &b) { | ||
if (a.second < b.second) return true; | ||
return false; | ||
} | ||
}; | ||
|
||
int main() { | ||
priority_queue<ii, vector<ii>, cmp> q; | ||
|
||
int n; cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
int a, b; cin >> a >> b; | ||
q.push(make_pair(a, b)); | ||
} | ||
|
||
int dest, fuel; cin >> dest >> fuel; | ||
int cur = 0, ans = 0; | ||
|
||
priority_queue<ii, vector<ii>, cmpB> reachable; | ||
|
||
while (cur <= dest) { | ||
while (!q.empty()) { | ||
if (q.top().first <= cur + fuel) { | ||
reachable.push(q.top()); | ||
q.pop(); | ||
} | ||
else break; | ||
} | ||
|
||
while (true) { | ||
if (cur + fuel >= dest) { | ||
printf("%d\n", ans); | ||
return 0; | ||
} | ||
|
||
if (reachable.empty()) { | ||
printf("-1\n"); | ||
return 0; | ||
} | ||
|
||
int f = reachable.top().first; | ||
int s = reachable.top().second; | ||
|
||
if (f > cur) fuel -= f - cur; | ||
fuel += s; | ||
|
||
cur = f > cur ? f : cur; | ||
ans++; | ||
|
||
reachable.pop(); | ||
|
||
if (q.top().first <= cur + fuel) break; | ||
} | ||
} | ||
|
||
printf("%d\n", ans); | ||
} |