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

zoj 1497 Ball Toss

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

zoj 1497 Ball Toss

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 35int n, m;int d[maxn];int dir[2] = {-1, 1};bool vis[maxn];void input(){    char st[5];    scanf("%d", &m);    m--;    for (int i = 0; i < n; i++)    {        scanf("%s", st);        if (st[0] == 'R') d[i] = 1;        else d[i] = 0;    }}int unify(int a){    return (a + n) % n;}void work(){    int s = m;    int t = unify(0 + dir[d[m]]);    if (t == m)        t = unify(t + dir[d[m]]);    int cnt = 1;    int ret = 1;    vis[m] = true;    memset(vis, 0, sizeof(vis));    while (cnt < n)    {        vis[s] = true;        d[s] = 1 - d[s];        ret++;        if (!vis[t]) cnt++;        int temp = unify(s + dir[d[t]]);        if (temp == t) temp = unify(temp + dir[d[t]]);        s = t;        t = temp;    }     printf("Classmate %d got the ball last after %d tosses.n", s + 1, ret);}int main(){    while (scanf("%d", &n), n)    {        input();        work();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368533.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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