// Codeforces Round #171 (Div. 2) A. Point on Spiral
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int x = 0;
int y = 0;
int xtgt = in.nextInt();
int ytgt = in.nextInt();
int turn = -1;
int dir = 0;
int step = 1;
while (true) {
turn++;
int newx = x;
int newy = y;
if (dir == 0) {
newx = x + step;
if (y == ytgt && x <= xtgt && xtgt <= newx)
break;
}
else if (dir == 1) {
newy = y + step;
step++;
if (x == xtgt && y <= ytgt && ytgt <= newy)
break;
}
else if (dir == 2) {
newx = x - step;
if (y == ytgt && x >= xtgt && xtgt >= newx)
break;
}
else if (dir == 3) {
newy = y - step;
step++;
if (x == xtgt && y >= ytgt && ytgt >= newy)
break;
}
x = newx;
y = newy;
dir++;
if (dir == 4)
dir = 0;
}
out.println(turn);
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int x = 0;
int y = 0;
int xtgt = in.nextInt();
int ytgt = in.nextInt();
int turn = -1;
int dir = 0;
int step = 1;
while (true) {
turn++;
int newx = x;
int newy = y;
if (dir == 0) {
newx = x + step;
if (y == ytgt && x <= xtgt && xtgt <= newx)
break;
}
else if (dir == 1) {
newy = y + step;
step++;
if (x == xtgt && y <= ytgt && ytgt <= newy)
break;
}
else if (dir == 2) {
newx = x - step;
if (y == ytgt && x >= xtgt && xtgt >= newx)
break;
}
else if (dir == 3) {
newy = y - step;
step++;
if (x == xtgt && y >= ytgt && ytgt >= newy)
break;
}
x = newx;
y = newy;
dir++;
if (dir == 4)
dir = 0;
}
out.println(turn);
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
No comments:
Post a Comment