04 Mar 2021 |
PS
AtCoder Beginner Contest 190 A번 Very Very Primitive Game
문제
https://atcoder.jp/contests/abc190/tasks/abc190_a

풀이
타카하시와 아오키가 서로 가진 사탕을 하나씩 먹을때 누가 마지막까지 사탕이 남아있는지 선택하는 문제
누가 더 사탕을 많이 가졌는지, 수가 같다면 누가 먼저 시작했는지만 잘 구분하면 되는 문제이다.
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc190/tasks/abc190_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll a,b,c;
cin >> a >> b >> c;
if(a > b){
cout << "Takahashi";
}
else if(b > a){
cout << "Aoki";
}
else{
if(c) cout << "Takahashi";
else cout << "Aoki";
}
return 0;
}
03 Mar 2021 |
PS
AtCoder Beginner Contest 189 C번 Mandarin Orange
문제
https://atcoder.jp/contests/abc189/tasks/abc189_c

풀이
(l,r,x)가 최대치가 되게끔 오렌지를 먹으려면 최대 몇개를 먹을 수 있는가를 묻는 문제
A <= 10000 이기 때문에 O(N^2logN) 으로 풀면 TLE가 나기 떄문에 O(N^2) 에서 해결해야한다.
l,r을 for-loop를 돌며 해당 범위의 최소값으로 갯수만큼 곱해주어 이를 반복하여 최대값을 찾아 출력
말이 어렵다면 아래 코드를 보면 금방 이해가 갈 것이다. :(
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc189/tasks/abc189_c
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vll a(n);
ll ans = 0;
rep(i,n) cin >> a[i];
rep(i,n){
ll m = a[i];
for(int j = i;j<n;j++){
m = min(m,a[j]);
ans = max(ans, (j-i+1)*m);
}
}
cout << ans;
return 0;
}
03 Mar 2021 |
PS
AtCoder Beginner Contest 189 B번 Alcoholic
문제
https://atcoder.jp/contests/abc189/tasks/abc189_b

풀이
타카하시는 알콜을 X 밀리리터 이상 섭취하면 취한다고 했을때
N개의 술의 용량과 도수가 주어질때 순서대로 먹는다고 하면 몇번째 술을 먹을때 취하는가 구하는 문제
용량과 도수를 곱하면 알코올양이 나오는것을 이용하여 계산하면 AC
N <= 1000 이기 때문에 O(N)으로도 무난하게 풀 수 있다.
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc189/tasks/abc189_b
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,x;
cin >> n >> x;
vll v(n), p(n);
ll temp = 0;
rep(i,n){
cin >> v[i] >> p[i];
temp += v[i] * p[i];
if(temp > x*100){
cout << i+1;
return 0;
}
}
cout << -1;
return 0;
}
03 Mar 2021 |
PS
AtCoder Beginner Contest 189 A번 Slot
문제
https://atcoder.jp/contests/abc189/tasks/abc189_a

풀이
이름에서 알 수 있듯이 슬롯머신을 의미하는 것이다.
문자 3개를 받아서 세 문자가 모두 일치하면 Won, 아니면 Lost 출력
코드
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc189/tasks/abc189_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
char s[3];
rep(i,3) cin >> s[i];
if(s[0] == s[1] && s[1] == s[2])
cout << "Won";
else
cout << "Lost";
return 0;
}
29 Jan 2021 |
Tutorial

기존에는 외부에서 가벼운 코딩을 하고자 할 때에는 아이패드로 jump desktop을 이용해서 집에 있는 맥미니에 원격을 붙여서 코딩을 하곤 했는데 원격 환경의 특성상 연결이 항상 깔끔하지 않아 많이 불편했는데 재밌는 레포지토리를 찾았습니다.
https://github.com/cdr/code-server
장점
- 깔끔한 환경
- 기존 vscode와 놀랍도록 유사
- vscode의 확장 또한 사용 가능
본 문서에선 code-server + Nginx에 HTTPS까지 적용하는 방법을 설명해 보곘습니다.
Mac OS를 기준으로 설명 되었습니다.
code-server
1. code-server 설치

brew가 설치되어 있지 않다면 brew를 먼저 설치해주세요
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. code-server 설정
nano ~/.config/code-server/config.yaml
code-server의 설정파일이 저장되어있는 파일입니다. 적절하게 설정값을 바꿔주세요
만약 해당 경로에 파일이 없다면 code-server를 실행하면 자동으로 생성됩니다.
brew services start code-server
3. code-server 재시작
brew services restart code-server
변경된 설정을 반영하기위해 code-server를 재시작합니다.

4. code-server 접속
code-server의 기본포트는 8080 입니다.
Nginx
code-server는 기본적으로 https 연결을 권장하기 때문에 Nginx를 이용하여 https환경 구축까지 해보겠습니다.
1. Nginx 설치

인텔맥과 M1맥의 Nginx 설치 경로가 다를 수 있어 본인의 디바이스의 Nginx 설치 경로를 파악하도록 합시다.
보통 Nginx 설치시 path가 적혀있긴 합니다.
2. nginx.conf 설정 변경
http {
...
...
...
include servers/*;
}
저는 /opt/homebrew/etc/nginx/nginx.conf 경로에 nginx.conf 파일이 위치하였습니다.
해당 파일을 열어 http {..} 내부의 맨 아래 include server/*;
를 추가해줍니다. 이는 server 폴더 내의 다른 파일들을 불러와서 Nginx 설정으로 사용하겠다는 의미입니다.
3. code-server 컨픽 작성
server {
listen 80;
listen [::]:80;
server_name mydomain.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
}
저는 /opt/homebrew/etc/nginx/server/code-server
경로에 해당 파일을 생성하여 위 코드와 같은 컨픽을 작성하였습니다. 해당 컨픽은 code-server 공식 레포에도 동일하게 작성되어 있습니다.
해당 컨픽을 작성하고 Nginx를 재시작하면 해당 도메인의 80번포트로 접속하게 되면 proxy_pass로 연결됩니다.
LetsEncrypt
마지막으로 https를 적용해 보겠습니다. 본 문서에서는 ssl 인증서를 무료로 발급해주는 LetsEncrypt를 사용합니다.
1. certbot 설치
2. certbot을 이용하여 SSL 인증서 생성
sudo certbot --non-interactive --redirect --agree-tos --nginx --nginx-server-root /opt/homebrew/etc/nginx -d mydomain.com -m my@email.com
nginx-server-root 옵션은 본인의 nginx 경로에 맞게 수정하여 입력해줍니다.
위 커맨드를 수행하면 자동으로 인증서 생성부터 nginx https 적용까지 수행됩니다.
정상적으로 진행했다면 아래 사진과 같이 https 연결이 가능해집니다.
