You are on page 1of 7

BEE MAJA

#include <iostream>

#include <algorithm>

using namespace std;

// 0,0 -> 1

// + 1

// 0,1 -> 2

// + 7

// 0,2 -> 9

// + 13

// 0,3 -> 22

// + 19

// 0,4 -> 41

// So each layer is 6 more nodes than previous

int numNodesBy0X[10000];

int xChange[] = {-1, 0, 1, 1, 0, 0, -1};

int yChange[] = {0, -1, -1, 0, 1, 1, 1};

int main()

int sum = 1, current = 1;

int yMax = 1;

for (; sum <= 100000; ++yMax, sum += current, current += 6)

numNodesBy0X[yMax] = sum;

int num;

while (cin >> num)

int *position = upper_bound(numNodesBy0X, numNodesBy0X + yMax, num);

--position;
int xCircleVal = 0;

int yCircleVal = position - numNodesBy0X - 1;

const int sideLength = yCircleVal;

int distanceLeft = num - *position;

for (int change = 0; distanceLeft; ++change)

int move = min(distanceLeft, sideLength);

if (change == 5)

move = min(move, 1);

xCircleVal += xChange[change] * move;

yCircleVal += yChange[change] * move;

distanceLeft -= move;

cout << xCircleVal << ' ' << yCircleVal << '\n';

}
MONOCYCLE
#include <algorithm>

#include <cctype>

#include <cmath>

#include <cstdio>

#include <cstring>

#include <iostream>

#include <map>

#include <queue>

#include <string>

#include <vector>

#define FileIn(file) freopen(file".inp", "r", stdin)

#define FileOut(file) freopen(file".out", "w", stdout)

#define FOR(i, a, b) for (int i=a; i<=b; i++)

#define REP(i, n) for (int i=0; i<n; i++)

#define Fill(ar, val) memset(ar, val, sizeof(ar))

#define PI 3.1415926535897932385

#define uint64 unsigned long long

#define int64 long long

#define all(ar) ar.begin(), ar.end()

#define pb push_back

#define bit(n) (1<<(n))

#define INF 500000000

#define maxN 30

using namespace std;

class Node {

public:

int x, y, dr, cl;

Node(int xx, int yy, int d, int c) {

x = xx; y = yy;

dr = d; cl = c;

};
const int dx[] = { -1, 0, 1, 0 };

const int dy[] = { 0, 1, 0, -1 };

const int k[] = { 1, 3 };

int n, m, d[maxN][maxN][4][5];

char s[maxN][maxN];

bool isInside(int x, int y) {

return (x >= 0 && x < n && y >= 0 && y < m);

int bfs(int x, int y) {

queue<Node> Q;

Q.push(Node(x, y, 0, 0));

d[x][y][0][0] = 0;

while (!Q.empty()) {

Node u = Q.front(); Q.pop();

int val = d[u.x][u.y][u.dr][u.cl];

if (s[u.x][u.y] == 'T' && !u.cl) return val;

x = u.x + dx[u.dr];

y = u.y + dy[u.dr];

int cl = (u.cl + 1) % 5;

if (isInside(x, y) && d[x][y][u.dr][cl]==INF && s[x][y]!='#') {

d[x][y][u.dr][cl] = val + 1;

Q.push(Node(x, y, u.dr, cl));

REP(i, 2) {

int dr = (u.dr + k[i]) % 4;

if (d[u.x][u.y][dr][u.cl]==INF) {

d[u.x][u.y][dr][u.cl] = val + 1;

Q.push(Node(u.x, u.y, dr, u.cl));

return -1;

}
main() {

// FileIn("test"); FileOut("test");

int x, y, Case = 0;

while (scanf("%d %d ", &n, &m) && (n || m)) {

REP(i, n) {

gets(s[i]);

REP(j, m) {

if (s[i][j]=='S')

x = i, y = j;

REP(k, 4)

REP(t, 5)

d[i][j][k][t] = INF;

int res = bfs(x, y);

if (Case) printf("\n");

printf("Case #%d\n", ++Case);

if (res < 0) puts("destination not reachable");

else printf("minimum time = %d sec\n", res);

Case #1

destination not reachable

Case #2

minimum time = 49 sec


Dermuba Triangle
from math import sqrt

from sys import stdin, stdout

h = 0.8660254037844386

h_3 = h/3

h_23 = 2*h/3

# Top of top triangle is axis (x=0, y=0.5)

def find_center_coord(index):

root = int(sqrt(index))

y = -root*h

if index % 2 == root % 2:

# .

# /\

# -----

y -= h_23

else:

# -----

# \/

# .

y -= h_3

disp = index - root*root

x = (0.5) * (disp-root)

return x, y

while True:

line = stdin.readline().strip()
if line == "":

break

line = line.split()

s, t = int(line[0]), int(line[1])

x1, y1 = find_center_coord(s)

x2, y2 = find_center_coord(t)

distance = sqrt((y1-y2)*2 + (x1-x2)*2)

stdout.write("{:.3f}\n".format(distance))

You might also like