1119 : Exploring Caves
解説
スタート位置から最も遠い部屋の座標を答える問題。
今の位置からのどれだけ移動するかが入力で与えられるので、その通りに移動して逐一距離を計算すればいい。
英語の勉強しましょう。
プログラム
C
C++
|
+
|
... |
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x = 0, y = 0;
int dx, dy;
int max = 0, tx, ty;
while (cin >> dx >> dy, dx || dy) {
x += dx;
y += dy;
int d = x*x + y*y;
if (max < d) {
max = d;
tx = x;
ty = y;
}
else if (max == d && tx < x) {
tx = x;
ty = y;
}
}
cout << tx << " " << ty << endl;
}
return 0;
}
|
Java
最終更新:2013年01月17日 20:06