24h購物| | PChome| 登入
2012-12-19 22:14:48| 人氣1,751| 回應1 | 上一篇 | 下一篇

[UVA][骰子同構] 11959 - Dice

推薦 0 收藏 0 轉貼0 訂閱站台

I  — Dice

Time Limit: 1 sec
Memory Limit: 32 MB

Mary add Sue are playing with dices. Rules are simple: at the begging each of them puts coin on the table and roll a dice. Wins a player who rolled a larger number. If numbers are the same, coins stay on the table for a next round. In order to make this game more interesting they decided to play now with normal dices, but with dice that can have arbitrary number of bones, from 0 till 9. However each round must be played with same dice by both players.

Girls have been playing this game for a day long, till Mary run out of coins (nevertheless she had more coins at the beginning of the game). Now Mary is confused. How could she have lost all her coins? She thinks that Sue had been cheating. Before each roll Mary wrote on a paper numbers of bones on each side of the dice. Now she wonders if same dice was always used during one round. Help her to find it out.

INPUT

On the first line there is the total number of test cases T (T ≤ 103), next T lines follows. Each line contains two six digit numbers, each digit stands for number of bones on side of a dice in this order: top, bottom, front, left, back, right.

OUTPUT

For each test case output line "Equal" if two dices are equals, or "Not Equal" otherwise.

SAMPLE INPUT

3
345678 345678
123123 123456
123456 351624

SAMPLE OUTPUT

Equal
Not Equal
Equal

Problem by: Aleksej Viktorchik; Leonid Sislo
Huge Easy Contest #2


把翻法都依序找出來,然後找一個最小表示法去做比較即可。

#include <stdio.h>
#include <stdlib.h>
typedef struct {
    int dice[6];
} DICE;
void Right_turn(DICE *A) {
    static int t;
    t = A->dice[0], A->dice[0] = A->dice[4];
    A->dice[4] = A->dice[3], A->dice[3] = A->dice[1], A->dice[1] = t;
}
void Up_turn(DICE *A) {
    static int t;
    t = A->dice[0], A->dice[0] = A->dice[5];
    A->dice[5] = A->dice[3], A->dice[3] = A->dice[2], A->dice[2] = t;
}
void clockwise(DICE *A) {
    static int t;
    t = A->dice[2], A->dice[2] = A->dice[4];
    A->dice[4] = A->dice[5], A->dice[5] = A->dice[1], A->dice[1] = t;
}
int cmp(const void *a, const void *b) {
    static DICE *i, *j;
    static int k;
    i = (DICE *)a, j = (DICE *)b;
    for(k = 0; k < 6; k++)
        if(i->dice[k] != j->dice[k])
            return i->dice[k] - j->dice[k];
    return 0;
}

DICE Spin_dice(DICE A) {
    static int i, j;
    DICE B = A;
    for(i = 0; i < 4; i++) {
        for(j = 0; j < 4; j++) {
            if(cmp(&B, &A) > 0)
                B = A;
            clockwise(&A);
        }
        Right_turn(&A);
    }
    Up_turn(&A);
    for(i = 0; i < 2; i++) {
        for(j = 0; j < 4; j++) {
            if(cmp(&B, &A) > 0)
                B = A;
            clockwise(&A);
        }
        Up_turn(&A), Up_turn(&A);
    }
    return B;
}
main() {
    int n, i;
    DICE A, B;// 前右上後左下
    char a[20], b[20]; // 上下前左後右
    scanf("%d", &n);
    while(n--) {
        scanf("%s %s", a, b);
        A.dice[0] = a[2];
        A.dice[1] = a[5];
        A.dice[2] = a[0];
        A.dice[3] = a[4];
        A.dice[4] = a[3];
        A.dice[5] = a[1];

        B.dice[0] = b[2];
        B.dice[1] = b[5];
        B.dice[2] = b[0];
        B.dice[3] = b[4];
        B.dice[4] = b[3];
        B.dice[5] = b[1];
        A = Spin_dice(A);
        B = Spin_dice(B);
        for(i = 0; i < 6; i++)
            if(A.dice[i] != B.dice[i])
                break;
        if(i == 6)
            puts("Equal");
        else
            puts("Not Equal");
    }
    return 0;
}

台長: Morris
人氣(1,751) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][floyd] 1056 - Degrees of Separation
此分類上一篇:[UVA][遞迴] 12041 - BFS (Binary Fibonacci String)

學生
不好意思
看到你寫的這個答案覺得你很厲害
可是我還是有很大一部分看不懂...
不知道能不能請問你 每一行的程式碼所要表達的意思是什麼.....?
是資結的鏈結串列的方法嘛@@?
謝謝你QQ
2012-12-22 08:22:13
版主回應
首先要先知道表示法有 24 種,把每一面都轉到a(前)的位置,然後順(逆)時針轉4圈,也就是 6*4 = 24種。
然後也沒有使用鏈結串列,你看到的->只是結構指標的表示形式。
2012-12-22 09:13:40
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文