SDNU 1049.盒饭(水题)

mac2022-06-30  25

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\n"); else printf("N\n"); return 0; }

 

转载于:https://www.cnblogs.com/RootVount/p/10883961.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)