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

zoj 1407 Packing Unit 4D Cubes

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

zoj 1407 Packing Unit 4D Cubes

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <map>using namespace std;int n,q[1000],inq[1000],con[1000][9],move[1000][9],sta[9];map<int,int> pos; bool solve(){   int head = 0,tail = 0;   inq[q[++tail] = 1] = 1;   while (head < tail){       int now = q[++head];       for (int i = 1;i <= 8;i ++) {int next = pos[con[now][i]]; if (con[now][i] && pos[con[next][((i + 1) ^ 1) - 1]] != now) return false; if (con[now][i] && !inq[pos[con[now][i]]]){    inq[q[++tail] = next] = 1;    for (int j = 1;j <= 8;j ++) move[next][j] = move[now][j];    move[next][i] = move[now][i] + 1;}       }   }   for (int i = 1;i <= n;i ++) if (!inq[i]) return false;    return true;}int main(){       int T;   cin>>T;   while (T--){       cin>>n;       pos.clear();       pos[0] = 0;        for (int i = 1;i <= n;i ++){int o;scanf("%d",&o);pos[o] = i; for (int j = 1;j <= 8;j ++){     int t;    scanf("%d",&t);    con[i][j] = t;}       }       memset(inq,0,sizeof inq);       memset(move,0,sizeof move);       if (!solve()) {puts("Inconsistent");continue;}       memset(sta,0,sizeof sta);       for (int i = 1;i <= n;i ++){for (int j = 1;j <= 8;j ++){    if (move[i][j] > sta[j]) sta[j] = move[i][j]; }       }       cout<<(sta[1] + sta[2] + 1) * (sta[3] + sta[4] + 1) * (sta[5] + sta[6] + 1) * (sta[7] + sta[8] + 1)<<endl;   }   return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379693.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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