From 6708e233d3863dee5e20eaf507bf9137ae87e843 Mon Sep 17 00:00:00 2001 From: kimsihwan <ksshhses@ajou.ac.kr> Date: Tue, 15 Feb 2022 11:42:54 +0900 Subject: [PATCH] 22.02.15 --- Greedy/1343.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ Greedy/14916.cpp | 27 +++++++++++++++++++ Greedy/2217.cpp | 32 +++++++++++++++++++++++ README.md | 3 +++ 4 files changed, 129 insertions(+) create mode 100644 Greedy/1343.cpp create mode 100644 Greedy/14916.cpp create mode 100644 Greedy/2217.cpp diff --git a/Greedy/1343.cpp b/Greedy/1343.cpp new file mode 100644 index 0000000..8170637 --- /dev/null +++ b/Greedy/1343.cpp @@ -0,0 +1,67 @@ +#include<iostream> +#include<string> +using namespace std; + +int main() +{ + string A = "AAAA"; + string B = "BB"; + string input, output = ""; + + cin >> input; + + int s = 0; + int flag = 0; + for(int i=0;i<input.length();i++) + { + if(input[i] == 'X') + continue; + + int len = i - s; + if(len % 2 == 1) + { + flag = 1; + break; + } + + int four, two; + + four = len/4; + len -= four * 4; + + two = len/2; + + for(int i=0;i<four;i++) + output += A; + for(int i=0;i<two;i++) + output += B; + output += "."; + + s = i + 1; + } + + int len = input.length() - s; + if(len % 2 == 1) + { + flag = 1; + } + else + { + int four, two; + + four = len/4; + len -= four * 4; + + two = len/2; + + for(int i=0;i<four;i++) + output += A; + for(int i=0;i<two;i++) + output += B; + } + + if(flag == 1) + cout << -1 << endl; + else + cout << output << endl; +} \ No newline at end of file diff --git a/Greedy/14916.cpp b/Greedy/14916.cpp new file mode 100644 index 0000000..06a6593 --- /dev/null +++ b/Greedy/14916.cpp @@ -0,0 +1,27 @@ +#include<iostream> +using namespace std; + +int main() +{ + int N; + cin >> N; + + int five, two; + + five = N/5; + N -= five * 5; + + if(N % 2 == 0) + two = N/2; + else + { + five--; + N+=5; + two = N/2; + } + + if(five < 0) + cout << -1 << endl; + else + cout << five + two << endl; +} \ No newline at end of file diff --git a/Greedy/2217.cpp b/Greedy/2217.cpp new file mode 100644 index 0000000..c408275 --- /dev/null +++ b/Greedy/2217.cpp @@ -0,0 +1,32 @@ +#include<iostream> +#include<vector> +#include<algorithm> +#include<functional> +using namespace std; + +int main() +{ + int N; + cin >> N; + + vector<int> v; + + for(int i=0;i<N;i++) + { + int a; + cin >> a; + v.push_back(a); + } + + sort(v.begin(), v.end(), greater<>()); + + int Max = 0; + for(int i=0;i<v.size();i++) + { + int now = (i + 1) * v[i]; + if(Max < now) + Max = now; + } + + cout << Max << endl; +} \ No newline at end of file diff --git a/README.md b/README.md index a64a912..de2501c 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,7 @@ ### 22.01.19 * Tree 끝 +### 22.02.15 + * Greedy 시작 + -- GitLab