Tenka1 Programmer Beginner Contest
A問題(100点)
文字列sの要素数が2だったらそのまま出力。
要素数が3だったらreverseして出力
#include <iostream> #include <numeric> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <iterator> #include <math.h> #include <cmath> #include <set> //#include <boost/math/common_factor_rt.hpp> #define ll long long using namespace std; int main() { ll a, b, k; cin >> a >> b >> k; for (int i = 1; i <= k; i++) { if (i % 2 != 0) { if (a % 2 != 0) { a -= 1; } b += a / 2; a = a / 2; } else { if (b % 2 != 0) { b -= 1; } a += b / 2; b = b / 2; } } cout << a << " " << b << endl; }
reverseは便利
B問題(200点)
K回ループを回して、iが奇数なら高橋君、偶数なら青木くんの処理を行う。
AorBが奇数なら一枚減らし、二分の一を一方の人に渡す処理を書けばおーけー。
#include <iostream> #include <numeric> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <iterator> #include <math.h> #include <cmath> #include <set> //#include <boost/math/common_factor_rt.hpp> #define ll long long using namespace std; int main() { ll a, b, k; cin >> a >> b >> k; for (int i = 1; i <= k; i++) { if (i % 2 != 0) { if (a % 2 != 0) { a -= 1; } b += a / 2; a = a / 2; } else { if (b % 2 != 0) { b -= 1; } a += b / 2; b = b / 2; } } cout << a << " " << b << endl; }
もっと効率よさそうなのありそう。
A,Bで10分以内に解けたのでよしとしよう。
C問題 400点
歯が立たず・・・・
解説見てから書きます。