boj step 9 rework & aloha graph1(16174,2606,1520)
This commit is contained in:
49
zeta_cpp/completed/1920.cpp
Normal file
49
zeta_cpp/completed/1920.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isExist(int x, int L[], int size) { // binsearch
|
||||
int begin = 0;
|
||||
int end = size - 1;
|
||||
int mid;
|
||||
int sep;
|
||||
while (begin <= end) {
|
||||
mid = (begin + end) / 2;
|
||||
sep = L[mid];
|
||||
if (x == sep) {
|
||||
return true;
|
||||
} else if (x < sep) {
|
||||
end = mid - 1;
|
||||
} else {
|
||||
begin = mid + 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N, M;
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(NULL);
|
||||
cout.tie(NULL);
|
||||
cin >> N;
|
||||
int A[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
cin >> A[i];
|
||||
}
|
||||
sort(A, A + N);
|
||||
|
||||
cin >> M;
|
||||
int x;
|
||||
for (int i = 0; i < M; i++) {
|
||||
cin >> x;
|
||||
if (isExist(x, A, N)) {
|
||||
cout << "1\n";
|
||||
} else {
|
||||
cout << "0\n";
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
29
zeta_cpp/completed/2501.cpp
Normal file
29
zeta_cpp/completed/2501.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int count = 1;
|
||||
int N, K;
|
||||
|
||||
cin >> N >> K;
|
||||
if(K == 1) {
|
||||
cout << 1 << endl;
|
||||
return 0;
|
||||
}
|
||||
for(int i=2;i<=N;i++) {
|
||||
if (N%i == 0) {
|
||||
count += 1;
|
||||
if (count == K) {
|
||||
cout << i << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (K > count) {
|
||||
cout << 0 << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
45
zeta_cpp/completed/9506.cpp
Normal file
45
zeta_cpp/completed/9506.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> isPerfect(int N) {
|
||||
vector<int> v;
|
||||
for (int i = 1; i < N; i++) {
|
||||
if (N % i == 0) {
|
||||
v.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
int result = accumulate(v.begin(), v.end(), 0);
|
||||
if (result == N) {
|
||||
return v;
|
||||
} else {
|
||||
return vector<int>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int input;
|
||||
vector<int> out;
|
||||
cin >> input;
|
||||
while (input != -1) {
|
||||
|
||||
out = isPerfect(input);
|
||||
if (out.size() > 0) {
|
||||
cout << input << " = " << out[0];
|
||||
for (int i = 1; i < out.size(); i++) {
|
||||
cout << " + " << out[i];
|
||||
}
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << input << " is NOT perfect." << endl;
|
||||
}
|
||||
cin >> input;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user