17 Jan 2021 |
PS
AtCoder Beginner Contest 188 B번 Orthogonality
문제
https://atcoder.jp/contests/abc188/tasks/abc188_b

풀이
길이가 n인 수열 A와 B가 있을때
의 합이 0이면 Yes 아니면 No를 출력
코드
#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/abc188/tasks/abc188_b
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vll a(n), b(n);
ll res = 0;
rep(i,n){
cin >> a[i];
}
rep(i,n){
cin >> b[i];
}
rep(i,n){
res += (a[i] * b[i]);
}
if(res == 0){
cout << "Yes";
}
else cout << "No";
return 0;
}
17 Jan 2021 |
PS
AtCoder Beginner Contest 188 A번 Three-Point Shot
문제
https://atcoder.jp/contests/abc188/tasks/abc188_a

풀이
농구를 하는데 현재 스코어가 X-Y 라고 한다면, 3점슛 한번으로 역전을 할 수 있는지 없는지 판별하는 문제
두 점수의 차가 2 이하가 되면 Yes, 그렇지 않으면 No를 출력한다.
코드
#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/abc188/tasks/abc188_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll x,y;
cin >> x >> y;
if(abs(x-y) <= 2) cout << "Yes";
else cout << "No";
return 0;
}
14 Jan 2021 |
PS
AtCoder Beginner Contest 187 D번 Choose Me
문제
https://atcoder.jp/contests/abc187/tasks/abc187_d

풀이
타카하시가 투표에서 이기려면 연설을 최소 몇번해야하는지 묻는 문제
x를 타카하시 투표수 - 아오키 투표수 라고 한다면
x는 i번 마을을 방문할 때 마다 2Ai+Bi 씩 증가함
x > 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/abc187/tasks/abc187_d
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vll x(n);
ll temp = 0;
ll ans = 0;
rep(i,n){
ll a,b;
cin >> a >> b;
temp -= a;
x[i] = a+a+b;
}
sort(all(x));
while(temp <= 0){
temp += x.back();
x.pop_back();
ans++;
}
cout << ans;
return 0;
}
14 Jan 2021 |
PS
AtCoder Beginner Contest 187 C번 1-SAT
문제
https://atcoder.jp/contests/abc187/tasks/abc187_c

풀이
set 자료형을 이용하여 손쉽게 해결 가능
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/abc187/tasks/abc187_c
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vector<string> s(n);
rep(i,n) cin >> s[i];
unordered_set<string> h(all(s));
rep(i,n){
if(h.count('!' + s[i])){
cout << s[i];
return 0;
}
}
cout << "satisfiable";
return 0;
}
14 Jan 2021 |
PS
AtCoder Beginner Contest 187 B번 Gentle Pairs
문제
https://atcoder.jp/contests/abc187/tasks/abc187_b

풀이
n개의 좌표가 입력으로 들어오고 두 점을 지나는 직선의 기울기 m이 -1 <= m <= 1 인 경우가 총 몇가지인지 구하는 문제
n <= 1000 이므로 O(n^2)으로 충분히 해결 가능한 문제이다.
코드
#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/abc187/tasks/abc187_b
ld slope(ll x1, ll y1, ll x2, ll y2){
return (ld)(y1-y2)/(ld)(x1-x2);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vll x(n);
vll y(n);
ll ans = 0;
rep(i,n) cin >> x[i] >> y[i];
for(int i = 0;i<n;i++){
for(int j = i+1;j<n;j++){
ld temp = slope(x[i],y[i],x[j],y[j]);
if(temp >= -1 && temp <= 1) ans++;
}
}
cout << ans;
return 0;
}