zoukankan      html  css  js  c++  java
  • SDNU 1049.盒饭(水题)

    Description

    有n个饭盒放成一排,其中第m个饭盒里多了一块牛肉。鲁观特别想吃带牛肉的那盒饭,但食堂阿姨说他只能先打开第一个饭盒,然后再向前移动两个饭盒,再向前移动三个饭盒,依此类推。当到达最后一个饭盒的时候,再回到第一个饭盒继续寻找,一共只允许找2 * m次。请你帮鲁观判断下是否能找到带牛肉的饭盒。

    Input

    第一行饭盒数n,第二行有牛肉的饭盒m
    (0 < n < 1000, 0 <= m < n)

    Output

    如果能吃到,输出"Y",如果不能吃到,输出"N"

    Sample Input

    5
    3

    Sample Output

    Y

    Hint

    初始状态为第0个饭盒。
    对于样例,一开始位置在第0个饭盒,第一次访问第1个饭盒,第二次访问第3个饭盒,可以找到。
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <map>
    using namespace std;
    
    int n, m, f[1000+8], sign, ying, miao, ga;
    
    int main()
    {
        memset(f, 0, sizeof(f));
        scanf("%d%d", &n, &m);
        f[m-1] = 1;
        int ii = 2, flag = 0;
        sign = 0;
        for(int i = 0; i<2*m; i++)
        {
            if(sign >= n)sign -= n;
            if(sign == m-1)
            {
                flag = 1;
                break;
            }
            sign += ii;
            ii++;
        }
        if(flag)printf("Y
    ");
        else printf("N
    ");
        return 0;
    }
  • 相关阅读:
    用代码初始化AE控件许可
    打开shpfile,mdb,sde工作空间
    UESTC_Tournament CDOJ 124
    UESTC_Little Deer and Blue Cat CDOJ 1025
    UESTC_Judgment Day CDOJ 11
    UESTC_One Step Two Steps CDOJ 1027
    UESTC_In Galgame We Trust CDOJ 10
    UESTC_贪吃蛇 CDOJ 709
    UESTC_冰雪奇缘 CDOJ 843
    java 常用API 时间
  • 原文地址:https://www.cnblogs.com/RootVount/p/10883961.html
Copyright © 2011-2022 走看看