#include <iostream> using namespace std; class KaIn { private: int M, N, x, y; public: KaIn(int _m, int _n, int _x, int _y); int GetCount(); }; KaIn::KaIn(int _m, int _n, int _x, int _y) { if (_m < _n) { this->M = _m; this->N = _n; this->x = _x; this->y = _y; } else { this->M = _n; this->N = _m; this->x = _y; this->y = _x; } } int KaIn::GetCount() { int _X = 1; int _Y = 1; bool IsOk = false; int Count = 1; while (true) { if (_X < this->M && _Y < this->N) { _X++; _Y++; Count++; } else if (_X == this->M && _Y < this->N) { _X = 1; _Y++; Count++; } else if (_X < this->M && _Y == this->N) { _X++; _Y = 1; Count++; } else if (_X == this->M && _Y == this->N) { _X = 1; _Y = 1; Count++; } if (_X == this->x && _Y == this->y) { IsOk = true; break; } if (_X == this->M && _Y == this->N) break; } if (this->x == this->M && this->y == this->N) return Count; else if (!IsOk) return -1; else return Count; } int main() { int testcase; cin >> testcase; while (testcase--) { int M, N, x, y; cin >> M >> N >> x >> y; KaIn Calendar(M, N, x, y); int Count = Calendar.GetCount(); cout << Count << endl; } }
# include < iostream > # include < vector > using namespace std ; int main ( ) { vector < int > Stick ; Stick . push_back ( 64 ) ; int Target ; cin > > Target ; int Last = 0 ; while ( true ) { if ( Target = = 64 ) break ; int Sum = 0 ; for ( int i = 0 ; i < Stick . size ( ) ; i + + ) Sum + = Stick [ i ] ; if ( Target = = Sum ) break ; else if ( Target < Sum ) { Stick [ Last ] / = 2 ; Sum = 0 ; for ( int i = 0 ; i < Stick . size ( ) ; i + + ) Sum + = Stick [ i ] ; if ( Target < = Sum ) continue ; else Stick . push_back ( Stick [ Last + + ] ) ; } } cout < < Stick . size ( ) ; ...
댓글
댓글 쓰기