Fu_L's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Fu-L/cp-library

:heavy_check_mark: dice
(src/others/dice.hpp)

Dice

サイコロ (乱数ではなく立体) を扱うライブラリです.

コンストラクタ

Dice d(int top, int front, int right, int left, int back, int bottom)

以下のようなサイコロを作ります.

roll_right, roll_left, roll_front, roll_back, roll_cw, roll_ccw, roll

(1) void d.roll_right()
(2) void d.roll_left()
(3) void d.roll_front()
(4) void d.roll_back()
(5) void d.roll_cw()
(6) void d.roll_ccw()
(7) void d.roll(int dir)

(1) サイコロを右方向に転がします.
(2) サイコロを左方向に転がします.
(3) サイコロを正面方向に転がします.
(4) サイコロを後ろ方向に転がします.
(5) サイコロを時計回りに回します.
(6) サイコロを反時計回りに回します.
(7) サイコロを以下の方向に転がします.

all_rotate

vector<Dice> all_rotate()

24通りの全ての置き方のサイコロを生成します.

Depends on

Verified with

Code

#pragma once
#include "../template/template.hpp"
#define roll_swap(x, a, b, c, d) swap(x.a, x.b), swap(x.b, x.c), swap(x.c, x.d);
struct Dice {
    int top, front, right, left, back, bottom;
    Dice(const int to = 1, const int fr = 2, const int ri = 3, const int le = 4, const int ba = 5, const int bo = 6)
        : top(to), front(fr), right(ri), left(le), back(ba), bottom(bo) {}
    void roll_right() {
        roll_swap((*this), top, left, bottom, right);
    }
    void roll_left() {
        roll_swap((*this), top, right, bottom, left);
    }
    void roll_front() {
        roll_swap((*this), top, back, bottom, front);
    }
    void roll_back() {
        roll_swap((*this), top, front, bottom, back);
    }
    void roll_cw() {
        roll_swap((*this), back, left, front, right);
    }
    void roll_ccw() {
        roll_swap((*this), back, right, front, left);
    }
    void roll(const int dir) {
        if(dir == 0) (*this).roll_front();
        if(dir == 1) (*this).roll_right();
        if(dir == 2) (*this).roll_back();
        if(dir == 3) (*this).roll_left();
    }
    friend bool operator<(const Dice& d1, const Dice& d2) {
        int vd1[] = {d1.top, d1.front, d1.right, d1.left, d1.back, d1.bottom};
        int vd2[] = {d2.top, d2.front, d2.right, d2.left, d2.back, d2.bottom};
        return vector<int>(vd1, vd1 + 6) < vector<int>(vd2, vd2 + 6);
    }
};

vector<Dice> all_rotate() {
    vector<Dice> res;
    res.reserve(24);
    Dice d;
    for(int i = 0; i < 6; ++i) {
        for(int j = 0; j < 4; ++j) {
            res.emplace_back(d);
            d.roll_cw();
        }
        if(i & 1) d.roll_front();
        else d.roll_right();
    }
    return res;
}
#line 2 "src/template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
#define rep(i, a, b) for(long long i = (a); i < (b); ++i)
#define rrep(i, a, b) for(long long i = (a); i >= (b); --i)
constexpr long long inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
#line 3 "src/others/dice.hpp"
#define roll_swap(x, a, b, c, d) swap(x.a, x.b), swap(x.b, x.c), swap(x.c, x.d);
struct Dice {
    int top, front, right, left, back, bottom;
    Dice(const int to = 1, const int fr = 2, const int ri = 3, const int le = 4, const int ba = 5, const int bo = 6)
        : top(to), front(fr), right(ri), left(le), back(ba), bottom(bo) {}
    void roll_right() {
        roll_swap((*this), top, left, bottom, right);
    }
    void roll_left() {
        roll_swap((*this), top, right, bottom, left);
    }
    void roll_front() {
        roll_swap((*this), top, back, bottom, front);
    }
    void roll_back() {
        roll_swap((*this), top, front, bottom, back);
    }
    void roll_cw() {
        roll_swap((*this), back, left, front, right);
    }
    void roll_ccw() {
        roll_swap((*this), back, right, front, left);
    }
    void roll(const int dir) {
        if(dir == 0) (*this).roll_front();
        if(dir == 1) (*this).roll_right();
        if(dir == 2) (*this).roll_back();
        if(dir == 3) (*this).roll_left();
    }
    friend bool operator<(const Dice& d1, const Dice& d2) {
        int vd1[] = {d1.top, d1.front, d1.right, d1.left, d1.back, d1.bottom};
        int vd2[] = {d2.top, d2.front, d2.right, d2.left, d2.back, d2.bottom};
        return vector<int>(vd1, vd1 + 6) < vector<int>(vd2, vd2 + 6);
    }
};

vector<Dice> all_rotate() {
    vector<Dice> res;
    res.reserve(24);
    Dice d;
    for(int i = 0; i < 6; ++i) {
        for(int j = 0; j < 4; ++j) {
            res.emplace_back(d);
            d.roll_cw();
        }
        if(i & 1) d.roll_front();
        else d.roll_right();
    }
    return res;
}
Back to top page