A - Obesity
体重[kg]÷身長[m]÷身長[m]
w / (h / 100) / (h / 100) >= 25.0
w * (100 / h) * (100 / h) >= 25.0
w * 100 * 100 >= 25.0 * h * h
C++
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
int main() {
double h, w;
cin >> h >> w;
if(w * 100 * 100 >= 25.0 * h * h){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}
B - Keep the Change
takeの時だけb-aを加算します。
x -= b;
y -= a;
if(s == "take") x += b - a;
C++
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
int main() {
int n;
cin >> n;
int x = 10000, y = 10000;
rep(i, n){
int a, b;
string s;
cin >> a >> b >> s;
x -= b;
y -= a;
if(s == "take") x += b - a;
}
cout << y - x << endl;
return 0;
}
C - Adjacent Sums (easy)
最初の値の奇数、偶数を決めると、その他の全ての値が決まります。
C++
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n), aa(n), b(n-1);
rep(i, n) cin >> a[i];
rep(i, n) aa[i] = a[i];
rep(i, n-1) cin >> b[i];
vector<int> ans(2, 0);
aa[0] = (aa[0] + 1) % 2;
ans[1]++;
rep(i, n-1){
if((a[i] + a[i+1]) % 2 != b[i]){
a[i+1]++;
ans[0]++;
}
if((aa[i] + aa[i+1]) % 2 != b[i]){
aa[i+1]++;
ans[1]++;
}
}
cout << min(ans[0], ans[1]) << endl;
return 0;
}
C++