diff --git a/10448.cpp b/10448.cpp new file mode 100644 index 0000000..2dc6b6b --- /dev/null +++ b/10448.cpp @@ -0,0 +1,37 @@ +// +// Created by LG on 2021-09-26. +// +#include + +using namespace std; + +int triangle(int t, int* tri){ + + for(int i=0; i<45; i++){ + for(int j=0; j<45; j++){ + for(int k=0; k<45; k++){ + if(tri[i] + tri[j] + tri[k] == t) + return 1; + } + } + } + return 0; +} + +int main(){ + int n; + cin >> n; + + int start = 1; + int tri[45]; + for(int i=2; i<47; i++){ + tri[i-2] = start; + start += i; + } + + for(int i=0; i> t; + cout << triangle(t, tri) << '\n'; + } +} diff --git a/20055.cpp b/20055.cpp new file mode 100644 index 0000000..eaecf41 --- /dev/null +++ b/20055.cpp @@ -0,0 +1,99 @@ +#include +#include + +using namespace std; + +void moveBelt(vector &durab, int &up, int &down, int n){ + if(up == 0) + up = 2*n-1; + else + up--; + if(down == 0) + down = 2*n-1; + else + down--; +} + +void moveRobot(vector &durab, int up, int down, vector &robot, int n){ + if(down>up){ + for(int i=down-1; i>up; i--){ + if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ + robot[i] = false; + robot[i+1] = true; + durab[i+1]--; + } + robot[down] = false; + } + } + else if(down=0; i--){ + if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ + robot[i] = false; + robot[i+1] = true; + durab[i+1]--; + } + robot[down] = false; + } + for(int i=2*n-1; i>up; i--){ + if(i==2*n-1){ + if(durab[0] > 0 && robot[i] && !robot[0]){ + robot[i] = false; + robot[0] = true; + durab[0]--; + } + } + else if(durab[i+1] > 0 && robot[i] && !robot[i+1]){ + robot[i] = false; + robot[i+1] = true; + durab[i+1]--; + } + robot[down] = false; + } + } +} + +int main(){ + int n, k, count = 1; + cin >> n >> k; + + int up = 0, down = n-1; + vector robot(2*n, false); //로봇 유무 + vector durab(2*n, 0); //내구도 + + //입력 + for(int i=0; i<2*n; i++){ + cin >> durab[i]; + } + + while(true){ + //1. 내리는 위치와 올리는 위치 옮김 + moveBelt(durab, up, down, n); + robot[down] = false; //내리는 위치 로봇 바로 내림. + + //2. 이동 가능한 로봇을 이동. + moveRobot(durab, up, down, robot, n); + + //3. 올리는 위치에 올림 + if(durab[up] != 0){ + robot[up] = true; + durab[up]--; + } + + //4. 내구도 0인 칸 세기 + int zero = 0; + for(int i=0; i<2*n; i++){ + if(durab[i] <= 0){ + zero++; + } + } + + //종료 조건 + if(zero >= k){ + cout << count; + break; + } + + count++; + } + +} \ No newline at end of file diff --git a/2108.cpp b/2108.cpp new file mode 100644 index 0000000..114e597 --- /dev/null +++ b/2108.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + + double sum = 0; //float은 틀린다. + int max = -4000, min = 4000; + int mid[n]; + int mode[8001] = {0, }; + + for(int i=0; i> t; + sum += t; + if(t > max) + max = t; + if(t < min) + min = t; + mid[i] = t; + mode[t+4000]++; + } + + cout << round(double(sum/n)) << '\n'; + + sort(mid, mid+n); + cout << mid[n/2] << '\n'; + + int k = -1; + int index = 0, count = 0; + for(int i=0; i<8001; i++){ + if(mode[i] > k){ + k = mode[i]; + index = i; + count = 0; + } + else if(mode[i] == k && count<1){ + count++; + index = i; + } + } + cout << index-4000 << '\n'; + + cout << max-min; + +} diff --git a/2858.cpp b/2858.cpp new file mode 100644 index 0000000..7bb2dd3 --- /dev/null +++ b/2858.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main() { + int r, b; + cin >> r >> b; + int area = r + b; + + int w=0, l=0; + for(int i=1; i +#include +#include + +using namespace std; + +int score(int n, map answer, vector hyunwoo){ + int count = 0; + for(int i=0; i> n; + + map answer; + for(int i=0; i> s; + answer.insert(pair(s, i)); + } + + vector hyunwoo(n); + for(int i=0; i> hyunwoo[i]; + } + + cout << score(n, answer, hyunwoo) << "/" << n*(n-1)/2; +} \ No newline at end of file