栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1630 Die

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1630 Die

#include<iostream>#include<algorithm>#include<set>#include<string>#include<cstring>#include<cstdio>using namespace std;enum {    SIZ = 38, };int num;int face[6][4] = {      {2, 5, 3, 4},       {2, 4, 3, 5},       {1, 5, 0, 4},       {0, 5, 1, 4},       {0, 3, 1, 2},       {0, 2, 1, 3}    };struct Node {    int ptr[6];};int mark[6];Node tr[SIZ];int st[SIZ], pos;void tail(){    int i, t;    t = 2;    for(i=0; i<6; i++){        if(mark[i] == 0){ st[t++] = i;        }    }    do {        for(i=0; i<6; i++){ tr[pos].ptr[st[i]] = i;        }        pos++;    } while(next_permutation(st+3, st+6));}void init(){        memset(mark, 0, sizeof(mark));    st[0] = 0; mark[0] = 1;    pos = 0;    for(int i=1; i<6; i++){        st[1] = i;        mark[i] = 1;        tail();        mark[i] = 0;    }}bool check(int p, int a, int b, int c){    int i;    a = tr[p].ptr[a];    b = tr[p].ptr[b];    c = tr[p].ptr[c];    for(i=0; i<4; i++){        if(face[a][i] == b) break;    }    if(i==4) return false;    i = (i+1)%4;    return (face[a][i] == c);}void fun(){        int i, j, a, b, c, t;    for(i=0; i<pos; i++){        st[i] = i;    }    t = pos;    while(num--){        scanf("%d%d%d",&a,&b,&c);        a--, b--, c--;        j = 0;        for(i=0; i<t; i++){ if(check(st[i], a, b, c)){     st[j++] = st[i]; }        }        t = j;    }    if(t > 1){        printf("=.-n");    } else if(t == 1){        j = st[0];        for(i=0; i<6; i++){ st[tr[j].ptr[i]] = i;        }        printf("%d", 1);        for(i=1; i<6; i++){ printf(" %d", st[i] + 1);        }        printf("n"); } else {        printf("T_Tn");    }}int main(){    init();    while( scanf("%d",&num) > 0){        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380598.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号