Almost Integer Rock Garden – HackerRank Solution Java , Python 3, Python 2 , C , C++, Best and Optimal Solutions , All you need.
Solutions of Algorithms Data Structures Hard HackerRank:
Here are all the Solutions of Hard , Advanced , Expert Algorithms of Data Structure of Hacker Rank , Leave a comment for similar posts
C++ Almost Integer Rock Garden HackerRank Solution
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
inline int pack(int x,int y){
return (x+25)*64 + (y+25);
}
inline void unpack(int p,int &x,int &y){
x = (p/64)-25;
y = (p%64)-25;
}
map<double,vi> mp;
vector<double> V;
int n;
map<double,int> rev;
vector<vi> answers;
vi ids;
void appen(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k,int l){
vi v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
v.push_back(e);
v.push_back(f);
v.push_back(g);
v.push_back(h);
v.push_back(i);
v.push_back(j);
v.push_back(k);
v.push_back(l);
int demi = answers.size();
answers.push_back(v);
double sum = 0.0;
REP(z,v.size()){
ids[v[z]] = demi;
sum += V[v[z]];
}
// printf("%.15f\n",sum);
}
int main(){
FOR(x,-12,13)FOR(y,-12,13){
int dst = x*x + y*y;
double sq = sqrt(dst);
int sqi = sq;
if(sqi!=sq)mp[sq].push_back(pack(x,y));
}
{
map<double,vi>::iterator iter = mp.begin();
while(iter != mp.end()){
double d = iter->first;
V.push_back(d);
iter++;
}
}
n = V.size();
REP(i,n)rev[V[i]] = i;
// go
ids.assign(n,-1);
appen(0,1,3,25,41,43,62,8,10,20,34,39);
appen(2,1,3,25,41,43,62,6,8,20,34,39);
appen(4,13,27,65,8,45,49,25,28,37,43,51);
appen(5,30,31,45,22,31,46,13,16,31,52,54);
appen(7,1,3,25,8,15,34,16,20,39,43,62);
appen(9,10,41,48,21,24,62,21,25,30,38,44);
appen(11,37,43,67,12,35,44,29,31,44,53,57);
appen(14,21,44,66,21,36,37,3,36,37,54,62);
appen(17,1,3,25,41,43,62,4,8,16,20,34);
appen(18,8,27,31,7,12,57,25,29,31,50,57);
appen(19,15,43,59,33,47,59,4,7,30,32,59);
appen(23,1,30,66,46,54,61,27,28,31,33,66);
appen(26,1,3,25,34,43,62,1,8,16,20,39);
appen(40,11,38,43,26,36,65,0,3,27,59,62);
appen(42,44,48,49,18,30,66,18,28,31,40,61);
appen(55,0,24,40,49,54,55,27,29,40,48,49);
appen(56,3,6,25,0,34,43,0,8,20,39,62);
appen(58,45,53,65,26,51,65,18,21,22,46,65);
appen(60,26,34,63,31,33,41,9,15,31,34,37);
appen(64,12,35,37,43,44,60,11,29,31,44,57);
int xx,yy;
scanf("%d%d",&xx,&yy);
double vv = sqrt(xx*xx+yy*yy);
int id = ids[rev[vv]];
vi vec = answers[id];
vi head(n,0);
bool poyo = false;
REP(i,vec.size()){
double ww = V[vec[i]];
if(!poyo && ww==vv){
poyo = true;
continue;
}
while(true){
int po = mp[ww][head[vec[i]]++];
int xxx,yyy;
unpack(po,xxx,yyy);
if(xx==xxx && yy==yyy)continue;
printf("%d %d\n",xxx,yyy);
break;
}
}
return 0;
}
Java Almost Integer Rock Garden HackerRank Solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static class P {
int x;
int y;
double d;
int c;
}
static P[] ps;
static int getPIndex(int x, int y) {
if(y > x) {
int c = x;
x = y;
y = c;
}
for (int i = 0; i < ps.length; i++) {
if(ps[i].x == x && ps[i].y == y) return i;
}
return -1;
}
static class F implements Comparable<F>{
int[] pi = new int[4];
double d;
@Override
public int compareTo(F o) {
return d < o.d ? -1 : d > o.d ? 1 : 0;
}
}
static F[] fs;
static int getFIndex(double d) {
int c0 = (int)(d * fs.length);
int a = c0 < 30000 ? 0 : c0 - 30000;
while(fs[a].d > d) {
a -= 30000;
if(a < 0) {
a = 0;
break;
}
}
int b = c0 + 30000 >= fs.length - 1 ? fs.length - 1 : c0 + 30000;
while(fs[b].d < d) {
b += 30000;
if(b >= fs.length - 1) {
b = fs.length - 1;
break;
}
}
// if(fs[a].d > d || fs[b].d < d) throw new RuntimeException();
while(b - a > 1) {
int c = (a + b) / 2;
if(d > fs[c].d) {
a = c;
} else {
b = c;
}
}
return Math.abs(d - fs[a].d) < Math.abs(d - fs[b].d) ? a : b;
}
static void buildP() {
List<P> list = new ArrayList<>();
for (int x = 1; x <= 12; x++) {
for (int y = 1; y <= x; y++) {
int d2 = x * x + y * y;
double d = Math.sqrt(d2);
int di = (int)Math.round(d);
if(di * di == d2) continue;
int c = x == y ? 4 : 8;
P p = new P();
p.x = x;
p.y = y;
p.d = d - Math.floor(d);
p.c = c;
list.add(p);
}
}
ps = list.toArray(new P[list.size()]);
// for (P p: ps) {
// System.out.println(p.x + " " + p.y + " " + p.d + " " + p.c);
// }
// System.out.println(ps.length);
}
static void buildF() {
int size = 74 * 75 * 76 * 77 / 24;
fs = new F[size];
int k = 0;
for (int i1 = 0; i1 < ps.length; i1++) {
for (int i2 = i1; i2 < ps.length; i2++) {
for (int i3 = i2; i3 < ps.length; i3++) {
for (int i4 = i3; i4 < ps.length; i4++) {
F f = new F();
f.pi = new int[]{i1,i2,i3,i4};
f.d = ps[i1].d + ps[i2].d + ps[i3].d + ps[i4].d;
f.d = f.d - Math.floor(f.d);
fs[k] = f;
k++;
}
}
}
}
Arrays.sort(fs);
}
static Random seed = new Random();
static class Result {
int[] result = new int[12];
double d12 = 0;
Result(int i0) {
result[0] = i0;
}
boolean flip() {
int k = seed.nextInt(7) + 1;
int ik = seed.nextInt(74);
result[k] = ik;
d12 = 0;
for (k = 0; k < 8; k++) {
d12 += ps[result[k]].d;
}
d12 = d12 - Math.floor(d12);
double add = 1 - d12;
int fi = getFIndex(add);
double d12r = d12 + fs[fi].d;
d12r = d12r - Math.floor(d12r);
if(d12r > 0.000000000001 && 1 - d12r > 0.000000000001) {
return false;
}
for (k = 0; k < 4; k++) {
result[k + 8] = fs[fi].pi[k];
}
d12 = d12r;
// System.out.println(d12);
return true;
}
}
static boolean checkResult(int[] result) {
int[] dist = new int[ps.length];
for (int i = 0; i < result.length; i++) {
if(i > 0 && result[i] == result[0]) return false; //for simplicity
dist[result[i]]++;
if(dist[result[i]] > 4) return false;
}
return true;
}
static void presentResult(int[] result, int x0, int y0) {
int[] dist = new int[ps.length];
dist[result[0]]++;
double d = ps[result[0]].d;
for (int i = 1; i < result.length; i++) {
int k = result[i];
dist[k]++;
int c = dist[k];
int x = ps[k].x, y = ps[k].y;
int d2 = x * x + y * y;
d += Math.sqrt(d2);
if(c == 1) {
System.out.println(ps[k].x + " " + ps[k].y);
} else if(c == 2) {
System.out.println((-ps[k].x) + " " + ps[k].y);
} else if(c == 3) {
System.out.println(ps[k].x + " " + (-ps[k].y));
} else if(c == 4) {
System.out.println((-ps[k].x) + " " + (-ps[k].y));
}
}
// System.out.println("d=" + d);
}
public static void solve(int x, int y) {
int xc = Math.abs(x), yc = Math.abs(y);
int i0 = getPIndex(xc, yc);
Result r = new Result(i0);
while(true) {
if(r.flip()) {
int[] result = r.result;
if(result == null || !checkResult(result)) continue;
double d = 0;
System.out.print("{");
for (int k = 0; k < 12; k++) {
if(k > 0) System.out.print(", ");
System.out.print(result[k]);
d += ps[result[k]].d;
}
System.out.println("},");
// presentResult(result, x, y);
break;
}
}
}
static void buildCache() {
buildF();
// long t = System.currentTimeMillis();
for (int i = 0; i < ps.length; i++) {
solve(ps[i].x, ps[i].y);
}
// long dt = System.currentTimeMillis() - t;
// System.out.println(dt);
}
static void solveWithCache(int x, int y) {
int xc = Math.abs(x), yc = Math.abs(y);
int i0 = getPIndex(xc, yc);
presentResult(cache[i0], xc, yc);
}
static void run() {
buildP();
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
solveWithCache(x, y);
}
public static void main(String[] args) {
run();
}
//Cache is built in 145 sec which is less than 2 seconds per one case
static int[][] cache = {
{0, 8, 40, 44, 24, 39, 3, 39, 4, 9, 18, 68},
{1, 36, 61, 35, 19, 34, 64, 43, 37, 50, 72, 72},
{2, 68, 33, 10, 68, 44, 62, 32, 37, 37, 43, 44},
{3, 55, 20, 39, 1, 17, 9, 47, 17, 18, 24, 44},
{4, 9, 71, 35, 56, 49, 15, 58, 24, 32, 34, 40},
{5, 69, 43, 22, 8, 36, 40, 57, 4, 54, 69, 69},
{6, 28, 37, 67, 50, 3, 37, 13, 37, 56, 64, 67},
{7, 39, 3, 0, 9, 18, 40, 70, 8, 24, 30, 44},
{8, 70, 9, 68, 24, 39, 9, 55, 0, 3, 9, 18},
{9, 1, 24, 0, 55, 70, 39, 3, 8, 18, 44, 54},
{10, 43, 37, 5, 37, 68, 32, 44, 26, 44, 62, 68},
{11, 51, 52, 31, 63, 32, 14, 40, 37, 38, 48, 48},
{12, 50, 3, 45, 45, 23, 70, 72, 23, 32, 32, 48},
{13, 68, 39, 17, 18, 4, 9, 24, 3, 4, 44, 55},
{14, 37, 51, 48, 55, 73, 11, 38, 31, 32, 42, 48},
{15, 69, 69, 43, 47, 55, 26, 3, 4, 22, 57, 69},
{16, 3, 44, 9, 1, 70, 24, 13, 7, 18, 39, 55},
{17, 4, 55, 70, 1, 44, 9, 13, 3, 18, 24, 54},
{18, 24, 9, 20, 4, 44, 70, 55, 3, 16, 16, 17},
{19, 36, 25, 72, 1, 37, 34, 72, 41, 43, 50, 61},
{20, 50, 36, 56, 15, 15, 15, 64, 37, 37, 37, 66},
{21, 71, 71, 64, 30, 42, 27, 56, 28, 58, 60, 71},
{22, 1, 4, 43, 69, 26, 36, 69, 30, 55, 57, 69},
{23, 48, 29, 70, 47, 36, 27, 46, 8, 10, 24, 65},
{24, 9, 68, 39, 70, 9, 40, 3, 0, 8, 9, 18},
{25, 55, 71, 15, 56, 49, 32, 58, 4, 9, 24, 34},
{26, 22, 47, 69, 40, 69, 69, 4, 3, 15, 43, 57},
{27, 8, 29, 54, 48, 24, 65, 10, 23, 36, 46, 70},
{28, 60, 23, 30, 58, 56, 64, 21, 42, 71, 71, 71},
{29, 68, 50, 45, 68, 57, 30, 70, 23, 48, 60, 60},
{30, 44, 3, 17, 39, 9, 13, 24, 7, 17, 18, 55},
{31, 42, 14, 48, 48, 73, 38, 40, 11, 32, 37, 51},
{32, 4, 35, 15, 58, 9, 40, 24, 34, 49, 56, 71},
{33, 21, 72, 21, 49, 48, 53, 61, 35, 36, 37, 65},
{34, 40, 32, 58, 71, 4, 56, 49, 9, 15, 24, 25},
{35, 4, 55, 15, 34, 58, 9, 32, 24, 49, 56, 71},
{36, 15, 37, 37, 67, 2, 50, 64, 5, 37, 56, 66},
{37, 31, 14, 38, 42, 55, 48, 32, 11, 48, 51, 73},
{38, 48, 11, 32, 55, 31, 42, 51, 14, 37, 48, 73},
{39, 70, 2, 44, 16, 18, 16, 3, 5, 9, 24, 55},
{40, 39, 24, 44, 8, 9, 3, 68, 0, 4, 18, 39},
{41, 37, 1, 61, 19, 50, 43, 72, 25, 34, 36, 72},
{42, 38, 37, 11, 31, 14, 48, 32, 48, 51, 55, 73},
{43, 36, 57, 69, 19, 47, 69, 4, 0, 22, 55, 69},
{44, 24, 17, 17, 30, 55, 39, 18, 3, 7, 9, 20},
{45, 60, 70, 27, 60, 47, 29, 54, 48, 50, 57, 68},
{46, 47, 10, 65, 29, 23, 27, 70, 8, 24, 36, 48},
{47, 9, 17, 3, 17, 24, 18, 55, 1, 20, 39, 44},
{48, 72, 51, 9, 54, 56, 71, 34, 19, 22, 50, 59},
{49, 24, 71, 4, 15, 32, 35, 56, 9, 34, 40, 58},
{50, 5, 36, 41, 36, 66, 2, 56, 36, 37, 37, 37},
{51, 52, 14, 48, 55, 48, 38, 32, 11, 31, 37, 63},
{52, 31, 37, 48, 63, 40, 32, 11, 14, 38, 48, 51},
{53, 3, 46, 71, 45, 70, 69, 55, 0, 11, 30, 34},
{54, 52, 68, 32, 10, 37, 37, 62, 1, 43, 44, 44},
{55, 9, 30, 7, 20, 70, 4, 44, 3, 17, 18, 24},
{56, 67, 37, 13, 3, 36, 64, 50, 3, 37, 37, 66},
{57, 5, 55, 22, 43, 4, 47, 8, 36, 69, 69, 69},
{58, 71, 34, 15, 40, 35, 4, 49, 9, 24, 32, 56},
{59, 71, 9, 72, 56, 19, 51, 50, 22, 34, 48, 54},
{60, 71, 56, 42, 28, 23, 30, 41, 21, 58, 71, 71},
{61, 41, 43, 25, 34, 36, 72, 19, 1, 37, 50, 72},
{62, 22, 31, 31, 31, 24, 38, 39, 18, 40, 49, 57},
{63, 51, 14, 37, 11, 48, 38, 31, 32, 48, 52, 55},
{64, 37, 0, 67, 37, 15, 56, 37, 8, 36, 50, 66},
{65, 23, 70, 8, 24, 27, 10, 46, 29, 36, 47, 48},
{66, 56, 67, 50, 67, 0, 37, 37, 3, 8, 37, 64},
{67, 64, 12, 56, 12, 66, 15, 37, 20, 36, 37, 37},
{68, 30, 62, 32, 7, 44, 52, 37, 10, 37, 43, 44},
{69, 11, 53, 71, 0, 3, 45, 55, 30, 34, 46, 70},
{70, 40, 1, 9, 24, 18, 5, 44, 2, 3, 39, 54},
{71, 22, 9, 47, 19, 59, 34, 48, 50, 51, 56, 72},
{72, 56, 22, 71, 51, 50, 34, 59, 9, 19, 48, 54},
{73, 31, 11, 51, 38, 42, 14, 37, 32, 48, 48, 55}
};
}
Python 3 Almost Integer Rock Garden HackerRank Solution
#!/bin/python3
import sys
import math
x0,y0 = [int(i) for i in input().strip().split(' ')]
u=[[0]*25 for _ in range(25)]
def use(y, x, v=1, c=1):
assert c > 0
for yy in (12 + y, 12 - y):
for xx in (12 + x, 12 - x):
if u[yy][xx] == 0:
u[yy][xx] = v; c-=1
if c == 0: return
if u[xx][yy] == 0:
u[xx][yy] = v; c-=1
if c == 0: return
assert 0
knownSol=[
[[1, 11], [1, 11], [2, 12], [3, 10], [3, 12], [4, 5], [4, 12], [4, 12], [6, 6], [6, 9], [7, 11], [7, 12]],
[[1, 10], [10, 10], [2, 11], [5, 10], [2, 10], [2, 10], [2, 5], [2, 4], [7, 8], [4, 9], [4, 9], [10, 11]],
[[1, 11], [1, 9], [1, 3], [3, 11], [1, 1], [8, 12], [3, 10], [10, 12], [4, 10], [3, 5], [7, 12], [4, 8]],
[[1, 8], [5, 11], [2, 11], [2, 11], [6, 12], [8, 12], [3, 10], [3, 8], [8, 11], [8, 11], [6, 10], [8, 10]],
[[4, 7], [5, 11], [2, 11], [2, 11], [6, 12], [8, 12], [3, 10], [3, 8], [8, 11], [8, 11], [6, 10], [8, 10]],
[[1, 12], [1, 10], [1, 9], [9, 11], [2, 9], [1, 2], [11, 12], [11, 12], [6, 6], [3, 9], [8, 10], [4, 9]],
[[1, 5], [1, 3], [2, 10], [7, 9], [1, 1], [6, 12], [5, 7], [2, 3], [4, 4], [5, 6], [6, 9], [6, 9]],
[[1, 6], [5, 9], [3, 11], [5, 8], [9, 10], [7, 8], [6, 10], [6, 10], [9, 9], [3, 5], [4, 9], [12, 12]],
[[1, 9], [1, 5], [7, 10], [6, 7], [2, 6], [3, 11], [6, 11], [5, 7], [2, 3], [10, 12], [7, 8], [4, 11]],
[[1, 5], [1, 3], [2, 10], [4, 6], [4, 6], [3, 3], [3, 11], [6, 12], [5, 7], [5, 6], [6, 9], [2, 2]],
[[8, 9], [5, 5], [1, 4], [1, 3], [2, 8], [4, 12], [4, 12], [4, 11], [8, 10], [4, 9], [4, 9], [4, 9]],
[[1, 12], [1, 7], [1, 4], [1, 3], [2, 8], [4, 12], [4, 12], [4, 11], [8, 10], [4, 9], [4, 9], [4, 9]],
[[1, 10], [5, 11], [3, 11], [2, 4], [3, 9], [2, 3], [3, 7], [3, 6], [7, 12], [7, 12], [7, 12], [7, 7]],
[[1, 11], [2, 12], [7, 10], [9, 11], [2, 9], [11, 12], [2, 7], [2, 7], [8, 8], [3, 9], [6, 10], [4, 9]],
[[1, 6], [10, 10], [5, 9], [3, 11], [5, 8], [9, 10], [11, 11], [7, 8], [6, 10], [6, 10], [3, 5], [4, 9]]
]
def hardcoded():
use(y0, x0, 2)
h2=(x0**2+y0**2)**.5
assert round(h2) != h2
loc0 = sorted([abs(x0), abs(y0)])
for sol in knownSol:
i0 = -1
for i in range(len(sol)):
x,y=sol[i]
if loc0==sol[i]: i0 = i; break
if i0 < 0: continue
for i in range(len(sol)):
if i == i0: continue
use(sol[i][1], sol[i][0])
return 1
return 0
hardcoded()
for y in range(25):
for x in range(25):
if u[y][x] != 1: continue
print(x-12, y-12)
Python 2 Almost Integer Rock Garden HackerRank Solution
x,y = raw_input().strip().split(' ')
x,y = [int(x),int(y)]
eggs=max(abs(x),abs(y))
why=min(abs(x),abs(y))
duplicates={(7,4):(8,1), (5,5):(7,1), (10,5):(11,2), (7,6):(9,2), (9,7):(11,3), (9,8):(12,1)}
if (eggs,why) in duplicates:
fish=duplicates[(eggs,why)]
eggs=fish[0]
why=fish[1]
# your code goes here
given=[(11, 7), (11, 1), (12, 2), (5, 4), (12, 3), (10, 3), (9, 6), (12, 7), (11, -1), (6, 6), (12, 4), (12, -4)]
bananas=[(10, 1), (12, 6), (6, 6), (8, 7), (5, 2), (4, 4), (9, 4), (11, 10), (10, 2), (10, -2), (12, -6), (9, -4)]
apples=[(9, 1), (11, 2), (10, 9), (12, 10), (11, 7), (5, 1), (12, 11), (10, 6), (6, 6), (7, 3), (11, 4), (10, 8)]
oranges=[(5, 1), (6, 4), (11, 3), (4, 2), (7, 1), (6, -4), (9, 6), (8, 4), (3, 1), (10, 2), (7, 5), (6, 5)]
pears=[(12, 11), (10, 9), (6, 6), (10, 8), (11, 7), (11, 2), (10, 6), (11, 4), (9, 1), (5, 1), (7, 3), (12, 10)]
melons=[(11, 5), (11, 2), (12, 7), (12, -7), (11, 3), (9, 3), (3, 2), (4, 4), (10, 1), (3, 3), (7, 3), (-12, 7)]
strawberries=[(3, 1), (11, 3), (10, 4), (8, 4), (11, 1), (9, 1), (1, 1), (5, 3), (12, 8), (10, 3), (12, 10), (12, 7)]
grapefruits=[(5, 1), (2, 1), (11, 3), (12, 8), (11, 2), (6, 4), (3, 2), (6, 5), (7, 1), (3, 1), (10, 2), (7, 5)]
tangerines=[(10, 2), (10, -2), (12, 6), (4, 4), (10, 1), (8, 7), (9, 4), (11, 10), (5, 2), (12, -6), (6, 6), (9, -4)]
peaches=[(11, 1), (10, 7), (8, 8), (9, 3), (12, 2), (11, 9), (7, 2), (10, 6), (9, 2), (12, 11), (7, -2), (9, 4)]
apricots=[(3, 1), (8, 2), (11, 4), (9, 4), (7, 1), (4, 1), (12, 4), (10, 8), (12, 1), (12, -4), (9, -4), (-9, 4)]
pomegranates=[(11, 5), (11, 3), (12, 7), (7, 7), (9, 3), (12, -7), (-12, 7), (8, 4), (10, 1), (2, 1), (3, 2), (7, 3)]
avocados=[(3, 1), (10, 2), (11, 3), (6, 3), (6, 4), (6, -4), (7, 5), (6, 5), (7, 1), (5, 1), (6, -3), (9, 6)]
lemons=[(10, 2), (12, 6), (9, 9), (9, 4), (10, -2), (1, 1), (9, -4), (11, 10), (10, 1), (5, 2), (12, -6), (8, 7)]
raspberries=[(7, 2), (4, 2), (7, 5), (9, 4), (5, 1), (12, 3), (8, 5), (9, -4), (9, 1), (6, 1), (10, 9), (10, -9)]
blueberries=[(5, 1), (3, 3), (6, 5), (2, 2), (11, 3), (12, 6), (7, 5), (3, 2), (3, 1), (10, 2), (6, 4), (12, 8)]
satsumas=[(11, 5), (12, 8), (11, 8), (10, 6), (8, 1), (10, 3), (8, 3), (8, 4), (12, 6), (12, -6), (11, -8), (10, 8)]
mangoes=[(6, 1), (10, 9), (10, 6), (9, 4), (10, 10), (8, 5), (11, 11), (10, -6), (9, 5), (11, 3), (8, 7), (5, 3)]
clementines=[(7, 1), (4, 1), (10, 8), (9, 4), (9, 3), (11, 4), (9, -4), (-9, 4), (12, 1), (8, 2), (6, 2), (12, 4)]
mandarins=[(10, 7), (9, 2), (3, 2), (12, 10), (9, 1), (6, 2), (11, 3), (11, 4), (5, 1), (11, 6), (7, 5), (8, 7)]
durians=[(12, 12), (8, 5), (10, 6), (10, -6), (10, 9), (8, 7), (9, 9), (9, 4), (6, 1), (9, 5), (11, 3), (5, 3)]
def answer(eggs,why):
for flowergarden in [given, bananas, apples, oranges, pears, melons, strawberries, grapefruits, tangerines, peaches, apricots, pomegranates, avocados, lemons, raspberries, blueberries, satsumas, mangoes, clementines, mandarins, durians]:
for rock in flowergarden:
if (eggs,why) == rock:
flowergarden.remove((eggs,why))
for f in flowergarden:
if f==(x,y) or f==(y,x):
print str(-f[1])+' '+str(-f[0])
else:
print str(f[0])+' '+str(f[1])
return
zeros=[(7, 1), (10, 2), (3, 2), (5, 1), (11, 3), (12, 8), (6, 5), (3, 1), (6, 4), (12, 6), (7, 5)]
for z in zeros:
print str(z[0])+' '+str(z[1])
return
answer(eggs,why)
C Almost Integer Rock Garden HackerRank Solution
#include <stdio.h>
#include <math.h>
int pnt[][12][16][2]={
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-10,-3}, {-10,3}, {-3,-10}, {-3,10}, {3,-10}, {3,10}, {10,-3}, {10,3}, },{{-9,-6}, {-9,6}, {-6,-9}, {-6,9}, {6,-9}, {6,9}, {9,-6}, {9,6}, },{{-12,-3}, {-12,3}, {-3,-12}, {-3,12}, {3,-12}, {3,12}, {12,-3}, {12,3}, },{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-7}, {-11,7}, {-7,-11}, {-7,11}, {7,-11}, {7,11}, {11,-7}, {11,7}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-5,-4}, {-5,4}, {-4,-5}, {-4,5}, {4,-5}, {4,5}, {5,-4}, {5,4}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-6,-2}, {-6,2}, {-2,-6}, {-2,6}, {2,-6}, {2,6}, {6,-2}, {6,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-8,-4}, {-8,4}, {-4,-8}, {-4,8}, {4,-8}, {4,8}, {8,-4}, {8,4}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-1,-1}, {-1,1}, {1,-1}, {1,1}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-2,-2}, {-2,2}, {2,-2}, {2,2}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-4,-4}, {-4,4}, {4,-4}, {4,4}, },{{-3,-3}, {-3,3}, {3,-3}, {3,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, }},
{{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}, },{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-9}, {-11,9}, {-9,-11}, {-9,11}, {9,-11}, {9,11}, {11,-9}, {11,9}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, },{{-9,-1}, {-9,1}, {-1,-9}, {-1,9}, {1,-9}, {1,9}, {9,-1}, {9,1}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, }},
{{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-7}, {-10,7}, {-7,-10}, {-7,10}, {7,-10}, {7,10}, {10,-7}, {10,7}, },{{-9,-6}, {-9,6}, {-6,-9}, {-6,9}, {6,-9}, {6,9}, {9,-6}, {9,6}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-6,-5}, {-6,5}, {-5,-6}, {-5,6}, {5,-6}, {5,6}, {6,-5}, {6,5}, }},
{{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-11,-7}, {-11,7}, {-7,-11}, {-7,11}, {7,-11}, {7,11}, {11,-7}, {11,7}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, }},
{{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-4,-1}, {-4,1}, {-1,-4}, {-1,4}, {1,-4}, {1,4}, {4,-1}, {4,1}, }},
{{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-4}, {-10,4}, {-4,-10}, {-4,10}, {4,-10}, {4,10}, {10,-4}, {10,4}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-4,-4}, {-4,4}, {4,-4}, {4,4}, },{{-12,-8}, {-12,8}, {-8,-12}, {-8,12}, {8,-12}, {8,12}, {12,-8}, {12,8}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-8,-3}, {-8,3}, {-3,-8}, {-3,8}, {3,-8}, {3,8}, {8,-3}, {8,3}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, }},
{{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-8,-8}, {-8,8}, {8,-8}, {8,8}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, }},
{{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-1,-1}, {-1,1}, {1,-1}, {1,1}, }},
{{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, }},
{{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, }},
{{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, }},
{{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-1}, {-9,1}, {-1,-9}, {-1,9}, {1,-9}, {1,9}, {9,-1}, {9,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-12,-3}, {-12,3}, {-3,-12}, {-3,12}, {3,-12}, {3,12}, {12,-3}, {12,3}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-7,-2}, {-7,2}, {-2,-7}, {-2,7}, {2,-7}, {2,7}, {7,-2}, {7,2}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, }},
{{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-8}, {-11,8}, {-8,-11}, {-8,11}, {8,-11}, {8,11}, {11,-8}, {11,8}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-7,-2}, {-7,2}, {-2,-7}, {-2,7}, {2,-7}, {2,7}, {7,-2}, {7,2}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-11,-6}, {-11,6}, {-6,-11}, {-6,11}, {6,-11}, {6,11}, {11,-6}, {11,6}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-8,-4}, {-8,4}, {-4,-8}, {-4,8}, {4,-8}, {4,8}, {8,-4}, {8,4}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, }},
{{{-12,-8}, {-12,8}, {-8,-12}, {-8,12}, {8,-12}, {8,12}, {12,-8}, {12,8}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-6,-5}, {-6,5}, {-5,-6}, {-5,6}, {5,-6}, {5,6}, {6,-5}, {6,5}, },{{-6,-4}, {-6,4}, {-4,-6}, {-4,6}, {4,-6}, {4,6}, {6,-4}, {6,4}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, }},
{{{-11,-11}, {-11,11}, {11,-11}, {11,11}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, }},
{{{-12,-12}, {-12,12}, {12,-12}, {12,12}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, }},
};
int garden[25][25];
int main(void) {
int x, y;
int i, j, k, m, c;
long double d=0;
scanf("%d%d", &x, &y);
d+=sqrtl(x*x+y*y);
garden[x+12][y+12]=1;
for (i=0; i<sizeof(pnt)/sizeof(pnt[0]); i++) {
for (j=0; j<12; j++) {
for (k=0; k<16 && pnt[i][j][k][0]; k++) {
if (pnt[i][j][k][0]==x && pnt[i][j][k][1]==y)
break;
}
if (k<16 && pnt[i][j][k][0]) {
for (k=0, c=0; c<11; k++) {
if (j==k)
continue;
for (m=0; m<16 && pnt[i][k][m][0]; m++) {
if (!garden[pnt[i][k][m][0]+12][pnt[i][k][m][1]+12]) {
garden[pnt[i][k][m][0]+12][pnt[i][k][m][1]+12]=1;
printf("%d %d\n", pnt[i][k][m][0], pnt[i][k][m][1]);
// d+=sqrtl(pnt[i][k][m][0]*pnt[i][k][m][0]+pnt[i][k][m][1]*pnt[i][k][m][1]);
c++;
break;
}
}
}
// printf("%.60Lf\n", d);
return 0;
}
}
}
return 0;
}
Leave a comment below
Similar Pair – HackerRank Solution
Gridland Provinces – HackerRank Solution