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

poj 1059 Chutes and Ladders

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

poj 1059 Chutes and Ladders

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int ran[1005],id,top;int getnext(){    return ran[id++];}int pos[10],to[105],flag[105];bool res[105];int main(){    int x,y;    top=0;    while(scanf("%d",&x),ran[top]=x)        top++;    int n;    while(scanf("%d",&n),n)    {        id=0;        memset(to,0,sizeof(to));        memset(flag,0,sizeof(flag));        memset(pos,0,sizeof(pos));        memset(res,false,sizeof(res));        while(scanf("%d%d",&x,&y),(x||y)) to[x]=y;        while(scanf("%d",&x),x) if(x<0)     flag[-x]=-1; else     flag[x]=1;        int p=0,d;        while(1)        { p++; if(p==n+1)     p=1; if(res[p]) {     res[p]=false;     continue; } d=getnext(); int t=pos[p]+d; if(t>100)     continue; if(to[t])     pos[p]=t=to[t]; else     pos[p]=t; if(t==100) {     printf("%dn",p);     break; } if(flag[t]<0)     res[p]=true; else if(flag[t]>0)     p--;        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379133.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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