05 Mar 2021 |
PS
AtCoder Beginner Contest 191 B번 Remove It
문제
https://atcoder.jp/contests/abc190/tasks/abc191_b

풀이
길이 N의 수열 A가 있을 때 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/abc191/tasks/abc191_b
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,x;
cin >> n >> x;
rep(i,n){
ll e;
cin >> e;
if(e != x) cout << e << " ";
}
return 0;
}
05 Mar 2021 |
PS
AtCoder Beginner Contest 191 A번 Vanishing Pitch
문제
https://atcoder.jp/contests/abc190/tasks/abc191_a

풀이
타카하시와 아오키가 야구를 한다. 타카하시는 투수고 아오키는 타자인데 타카하시는 미친 마구를 던진다.
바로 보이지 않는 공을 던진다고 한다. Vm/s로 공을 던지는데 공을 던진 이후 T초부터 S초 사이는 안보인다고 했을때
D 미터 떨어져있는 아오키는 공을 칠 수 있을까?
아오키가 Vt <= D <= vs 사이에 있으면 공이 보이지 않아서 칠 수 없다!
그러면 저 범위가 아니라면 공을 칠 수 있는것
코드
#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/abc191/tasks/abc191_a
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll v,t,s,d;
cin >> v >> t >> s >> d;
if(d < v*t || d > v*s) cout << "Yes";
else cout << "No";
return 0;
}
04 Mar 2021 |
PS
AtCoder Beginner Contest 190 D번 Staircase Sequences
문제
https://atcoder.jp/contests/abc190/tasks/abc190_d

풀이
정수 N이 있을때 어떠한 연속 수열을 더했을때 N이 되는 경우의 수가 몇개인지 찾는 문제
N의 약수 i중 (2N/i)- i + 1이 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/abc190/tasks/abc190_d
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
ll ans = 0;
for(ll i = 1;i*i<=n;i++){
if(n % i == 0){
if(i % 2 == 1) ans++;
if(n/i != i && (n/i)%2 == 1) ans++;
}
}
cout << ans * 2;
return 0;
}
04 Mar 2021 |
PS
AtCoder Beginner Contest 190 C번 Bowls and Dishes
문제
https://atcoder.jp/contests/abc190/tasks/abc190_c

풀이
접시가 N개가 있을때 m개의 조건이 있다 각 조건은 ai,bi번 접시에 공이 있다면 만족하는 조건이라고 할 때
k명의 사람이 각 ci 혹은 di번의 접시에 공을 놓는다고 할때 최대 몇개의 조건을 만족할까
k명의 사람이 ci 혹은 di를 선택하는 조건을 0 혹은 1로 생각하자
그러면 k명의 사람이 무언가를 선택하는것을 k-bits로 나타낼 수 있다.
K는 16보다 작기 떄문에 이를 모두 체크하여 최대값을 얻으면 정답
코드
#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_c
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,m;
cin >> n >> m;
vll a(m), b(m);
rep(i,m) cin >> a[i] >> b[i];
ll k;
cin >> k;
vll c(k), d(k);
rep(i,k) cin >> c[i] >> d[i];
ll ans = 0;
ll k2 = 1 << k;
for (int i = 0 ; i < k2; i++) {
vector<int> dish(n + 1);
for (int s = 0; s < k; s++) {
if (i >> s & 1) {
dish[c[s]]++;
} else {
dish[d[s]]++;
}
}
ll now = 0;
for (int i = 0; i < m; i++) {
if (dish[a[i]] == 0) continue;
if (dish[b[i]] == 0) continue;
now++;
}
ans = max(ans, now);
}
cout << ans;
return 0;
}
04 Mar 2021 |
PS
AtCoder Beginner Contest 190 B번 Magic 3
문제
https://atcoder.jp/contests/abc190/tasks/abc190_b

풀이
타카하시가 어떤 몬스터와 싸우는데 그 몬스터는 S초 이상걸리는 공격은 다 피해버리고, D보다 낮은 공격은 싹다 무시해버린다.
그럴때 과연 타카하시는 몬스터를 때릴 수 있을까?
N개의 (x,y) 쌍을 모두 체크하여 한번이라도 조건안에 들어오면 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--)
string ans[2] = {"No", "Yes"};
// https://atcoder.jp/contests/abc190/tasks/abc190_b
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,s,d;
cin >> n >> s >> d;
vll x(n), y(n);
ll isPossible = false;
rep(i,n) cin >> x[i] >> y[i];
rep(i,n){
if(x[i] < s && y[i] > d) isPossible = true;
}
cout << ans[isPossible];
return 0;
}