首页 > 其他 > 详细

Dice game

时间:2021-07-06 23:30:12      阅读:24      评论:0      收藏:0      [点我收藏+]

题目:

https://codeforces.com/group/d3FEQxSUNi/contest/335515/problem/D

最开始是1朝上

#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
const int mm=1e4+7;
int dis[mm],vis[mm]={0};
int d[7][5]={{0,0,0,0},{2,3,4,5},{1,3,4,6},{1,2,5,6},{1,2,5,6},{1,3,4,6},{2,3,4,5}};
struct node
{
    int top;
    int num;
};
node nod[mm];
queue<node> q;

void bfs()
{

        dis[1]=0;
        vis[0]=1;
        node start;
        start.top=1;
        start.num=0;
        q.push(start);

    while(!q.empty())
    {
        node st=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        { int res=st.num+d[st.top][i];

            if(!vis[res]&&res<=10000&&res>=1)
            {  vis[res]=1;
                 dis[res]=dis[st.num]+1;
                 node w;
                 w.top=d[st.top][i];
                 w.num=res;
                 q.push(w);
            }

        }
    }
}
int main()
{
    int t;
    scanf("%d",&t);
     memset(vis,0,sizeof(vis));
    memset(dis,0,sizeof(dis));
     bfs();
    while(t--)
    {
    int n;
        scanf("%d",&n);
        {  if(vis[n]==0)
          printf("-1\n");
          else
             printf("%d\n",dis[n]);
        }
    }

}

 

Dice game

原文:https://www.cnblogs.com/aacm/p/14978666.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!