-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 feat: initial commit for pat advanced 1168 to 1171 using C++
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 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,22 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
using namespace std; | ||
int num; | ||
string s; | ||
int is_prime(int x) { | ||
if (x < 2) return 0; | ||
for (int i = 2; i <= sqrt(x); i++) | ||
if (x % i == 0) return 0; | ||
return 1; | ||
} | ||
int main(){ | ||
cin >> s; | ||
num = s.size(); | ||
while (s.size()) { | ||
cout << s << ' ' << (is_prime(stoi(s)) ? "Yes" : "No") << '\n'; | ||
if (is_prime(stoi(s))) --num; | ||
s.erase(s.begin()); | ||
} | ||
if (num == 0) cout << "All Prime!"; | ||
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,41 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
int N, M, flag2, A[11][1001], mark[200005], out[11]; | ||
vector<int> used(2); | ||
int main(){ | ||
cin >> used[0] >> used[1]; | ||
mark[used[0]] = mark[used[1]] = 1; | ||
cin >> N >> M; | ||
for (int i = 1; i <= N; i++) | ||
for (int j = 1; j <= M; j++) cin >> A[i][j]; | ||
for (int i = 1; i <= M; i++) | ||
for (int j = 1; j <= N; j++) { | ||
if (out[j]) continue; | ||
int flag = 0; | ||
if (mark[A[j][i]]) flag = -1; | ||
for (auto it : used) { | ||
if (mark[it + A[j][i]] == 1) { | ||
mark[A[j][i]] = 1; | ||
flag++; | ||
used.push_back(A[j][i]); | ||
break; | ||
} | ||
} | ||
if (flag <= 0) { | ||
out[j] = 1; | ||
cout << "Round #" << i << ": " << j << " is out.\n"; | ||
} | ||
} | ||
for (int i = 1; i <= N; i++) { | ||
if (!out[i]) { | ||
if(!flag2) { | ||
cout << "Winner(s):"; | ||
flag2 = 1; | ||
} | ||
cout << " " << i; | ||
} | ||
} | ||
if (!flag2) cout << "No winner."; | ||
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,38 @@ | ||
#include <iostream> | ||
#include <map> | ||
#include <vector> | ||
using namespace std; | ||
int N, R, K, M, flag, E[505][505]; | ||
int main() { | ||
cin >> N >> R >> K; | ||
for (int i = 1, u, v; i <= R; i++) { | ||
cin >> u >> v; | ||
E[u][v] = E[v][u] = 1; | ||
} | ||
for (cin >> M; M; M--) { | ||
map<int, vector<int>> A; | ||
for (int i = 1, a; i <= N; i++) { | ||
cin >> a; | ||
A[a].push_back(i); | ||
} | ||
if(A.size() > K) cout << "Error: Too many species.\n"; | ||
else if (A.size() < K) cout << "Error: Too few species.\n"; | ||
else { | ||
flag = 1; | ||
for (auto it : A) { | ||
for (int i = 0; i < it.second.size(); i++) { | ||
for (int j = i + 1; j < it.second.size(); j++) { | ||
if(E[it.second[i]][it.second[j]]) { | ||
flag = 0; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if (flag) cout << "Yes\n"; | ||
else cout << "No\n"; | ||
} | ||
|
||
} | ||
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,29 @@ | ||
#include <iostream> | ||
#include <queue> | ||
using namespace std; | ||
int N, M, A[100005], index, now; | ||
priority_queue<int, vector<int>, greater<int>> Q1, Q2; | ||
int main(){ | ||
cin >> N >> M; | ||
for (int i = 1; i <= N; i++) { | ||
cin >> A[i]; | ||
if (i <= M) Q1.push(A[i]); | ||
} | ||
index = M + 1; | ||
while (Q1.size()) { | ||
now = Q1.top(); | ||
cout << now; | ||
Q1.pop(); | ||
if(index <= N) { | ||
if (A[index] < now) Q2.push(A[index]); | ||
else Q1.push(A[index]); | ||
++index; | ||
} | ||
if (Q1.size()) cout << ' '; | ||
else { | ||
swap(Q1, Q2); | ||
cout << '\n'; | ||
} | ||
} | ||
return 0; | ||
} |