03 Jan 2021 |
PS
AtCoder Beginner Contest 184 A번 Determinant
문제
https://atcoder.jp/contests/abc184/tasks/abc184_a

풀이
입력받은 2x2 행렬의 행렬값을 구하면 되는 문제
코드
#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/abc184/tasks/abc184_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll a,b,c,d;
cin >> a >> b >> c >> d;
cout << a*d - b*c;
return 0;
}
03 Jan 2021 |
PS
AtCoder Beginner Contest 183 C번 Travel
문제
https://atcoder.jp/contests/abc183/tasks/abc183_c

풀이
1번 도시에서 시작하여 모든 도시를 찍고 다시 1번도시로 돌아오는 루트를 구성할 때
정확하게 k시간이 걸리는 루트는 총 몇개인지 찾는 문제
DFS로 모든 케이스를 구성하여 그 값이 k와 일치하는것이 몇개인지 카운트하면 정답
코드
#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/abc183/tasks/abc183_c
ll n, k;
ll a[10][10] = {0,};
ll ans = 0;
ll isVisited[10] ={0,};
void dfs(int u , int cnt , int sum)
{
if(cnt == n - 1)
{
sum += a[u][1];
if(sum == k) ans ++ ;
return ;
}
isVisited[u] = 1;
repn(i , n)
{
if(isVisited[i]) continue ;
isVisited[i] = 1;
dfs(i , cnt + 1 , sum + a[u][i]);
isVisited[i] = 0;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
repn(i,n){
repn(j,n){
cin >> a[i][j];
}
}
dfs(1,0,0);
cout << ans;
return 0;
}
03 Jan 2021 |
PS
AtCoder Beginner Contest 183 B번 Billiards
문제
https://atcoder.jp/contests/abc183/tasks/abc183_b

풀이
시작지점 (sx,sy)가 있고 목적지점 (gx,gy)가 있을때 x축으로 공을쳐 쿠션을 이용하여 목적지점에 공을 도달하고자 할 때 어느지점을 조준해야하는지 찾는 문제

위 사진과 같이 직선으로 만들고 해당 직선의 x절편을 구하면 정답
코드
#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/abc183/tasks/abc183_b
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll sx,sy,gx,gy;
cin >> sx >> sy >> gx >> gy;
if(sx > gx){
swap(sx,gx);
swap(sy,gy);
}
ll b = sy + gy;
cout << fixed;
cout.precision(10);
cout << (ld)(sy*gx+sx*gy)/(ld)b;
return 0;
}
03 Jan 2021 |
PS
AtCoder Beginner Contest 183 A번 ReLU
문제
https://atcoder.jp/contests/abc183/tasks/abc183_a

풀이
ReLU를 구현하는 문제
ReLU는 입력값이 0보다 작으면 0으로 출력, 0보다 크면 입력값 그대로 출력하는 함수이다.
코드
#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/abc183/tasks/abc183_a
ll ReLU(ll x){
if(x >= 0) return x;
else return 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll x;
cin >> x;
cout << ReLU(x);
return 0;
}
03 Jan 2021 |
PS
AtCoder Beginner Contest 182 C번 To 3
문제
https://atcoder.jp/contests/abc182/tasks/abc182_c

풀이
0이 아닌 정수 N이 주어졌을때 몇개의 숫자를 지워 3의 배수로 만들 수 있는지 구하는 문제
임의의 정수가 3의 배수가 되려면 모든 자릿수의 합이 3의 배수가 되어야 한다.
즉 N의 자릿수의 합을 3으로 나눈 나머지가 0이면 답은 0으로 확정.
N의 자릿수의 합을 3으로 나눈 나머지가 1이면 1을 1번지우거나 2를 2번지워서 0으로 만들 수 있다.
N의 자릿수의 합을 3으로 나눈 나머지가 2이면 2를 1번지우거나 1을 2번 지워서 0으로 만들 수 있다.
위 경우에 포함되지 않는다면 3의 배수로 만들 수 없다.
코드
#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/abc182/tasks/abc182_c
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string n;
cin >> n;
ll len = n.length();
ll val=0, one=0, two=0;
for(auto k : n){
ll temp = k - '0';
val += temp;
if(temp % 3 == 1) one++;
else if(temp % 3 == 2) two++;
}
val = val % 3;
if(val == 0) cout << 0;
else if((val == 1 && one > 0 && len > 1) || (val == 2 && two > 0 && len > 1)) cout << 1;
else if((val == 1 && two > 1 && len > 2) || (val == 2 && one > 1 && len > 2)) cout << 2;
else cout << -1;
return 0;
}